0% found this document useful (0 votes)
81 views7 pages

Condition Program Day1 (If Condition)

Uploaded by

Land lord
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views7 pages

Condition Program Day1 (If Condition)

Uploaded by

Land lord
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

STRING FORMATTING:

--------------------
These are used to infused at a runtime and this can be done in 3 ways.

[Link] with placeholders

[Link] with .format()

[Link] with string literals __> f literals

#1. FORMATTING WITH PLACEHOLDERS

OLDEST METHOD OF STRING FORMATTING HERE USE MODULUS(%) OPERATOR.

#1. %s is used for inject string.

#2 %d is used for inject digits.

#3 %f is used to inject float values.

'''
# s="my name is %s and i am %d years old"%('karthik',15)
# print(s)

#2 FORMATTING WITH .FORMAT()

# a="my name is {} and i'm {} year old".format('karthik',20)


# print(a)

#FORMATTING WITH STRING LITERALS ---> f literals

# here we can use outside variable directly into the string instead of pass them as
a argument.
#boundary is { }

# when you are using f literals you need to add a letter "f" before the string
starts.

# a="karthik"
# b=20
# print(f"hello guys i'm {a} and i'm {b} years old")

-----------------------------------------------------------------------------------
------------------------------------------------------------------

flow control
statements:

*controlling the flow of program execution is called as flow control statements.


*flow control stmt is classified into 2 types,

[Link] flow control stmt


[Link] flow control stmt

[Link] flow control stmt:


********************************
*controlling a flow of program execution basedon condition is called as conditional
flow control stmt.

*conditional stmt is classified into 4 types,


[Link] if

[Link]-else

[Link]

[Link] if-else

[Link] if:
************
*if condition become True "if block/True State Block" will get execute else it will
just go with flow of program execution.

OR

*if the given condition become True it will execute in True state block state and
if the given condition is not satisfied just it will retun none

syntax:
*******

if cond:
stmt1 }
stmt2 }---> TSB/if block
stmt3 }

NOte:-->
drawback of simple-if:
**********************
*if cond is False we dont have any specific block of code to execute, to over this
we go "if-else"
"""

program example with solution:------------------------------>

# [Link] to check the number is odd (take user input)

num=int(input("enter the number: "))


if num%2==1:
print(f'the given number is odd {num}')

#[Link] to check the number is even (take user input)


num=int(input("enter the number: "))
if num%2==0:
print(f'the given number is odd {num}')

#[Link] to check if the student has scored 70% print "good luck "(take user input)

num=int(input("enter the number: "))


if num>=70:
print("good luck")

#[Link] to check which number is greater useing if condition

a=98
b=67
if a>b:
print(f'here {a} value is greater than {b}')

#[Link] to check if the given string has even length of character

s="hey guys you all are osam"


if len(s)%2==0:
print("its even length characters")

#[Link] to check if the given number is divisible by 5 (take user input)


num1=int(input("enter the number"))
if num1%5==0:
print("its divisible by 5")

#[Link] to check if the given programming is present in the list


p=["java","python","c","c++","RUBy","golang"]

a=input('enter the language')


if a in p:
print("the language is present")

#[Link] to check eligible to vote take user input as a age


age=int(input("enter the age: "))
if age>=18:
print("elgiable for the voting")

#[Link] to check if the given number is postive take user input

num=int(input("enter the number"))


if num>0:
print("its postive number")

#[Link] to check if the given string is palindrome (take user input)


a=eval(input("enter the data"))
if a==a[::-1]:
print("its palindrome data")

#[Link] to check if the first letter in the given string is consonent

s="lahari is a good student"


if s[0] not in "aeiou":
print("start with consonent")

# # [Link] to check the given string is uppercase or not (take user input)

a=str(input("enter the character"))


if [Link]():
print("its uppercase")

#[Link] to check the given value is string (take user input)

a=eval(input("enter the character: "))


if isinstance(a,str):
print("its string")

# OR

a=eval(input("enter the character: "))


if type(a)==str:
print("its string")

#[Link] to display "Python Coding" if the number is greater than 1 and lessthan 5
(take user input)

number=int(input("enter the number: "))


if number>1 and number<5:
print("Python Coding")

#[Link] to check whether given number is negative and print "its negative guys"

n=int(input("enter the number: "))


if n<0:
print("its negative guys")

#[Link] to check whether given input is divisible by 2 and 6 if condition is


True ,convert the given number to complex number.(take user input)

s=int(input("enter the number:"))


if s%2==0 and s%6==0:
print(complex(s))

#[Link] to check whether the given number is even or not,if even store the value
inside the list (take user input)

num=int(input("enter the number: "))


l=[]
if num%2==0:
l=l+[num]
print(l)

#with useing inbuilt function

num=int(input("enter the number: "))


l=[]
if num%2==0:
[Link](num)
print(l)

#[Link] to check whether a given value is divisible by 5 and 7,if the value is
divisible then display the square of the values (take user input)

nu=int(input("enter the number:")) #-->35


if nu%5==0 and nu%7==0:
print(nu**2)

#[Link] to check whether a given value is present in between 45 and 200 and the
number should be divisible by 4 and 5 ,if satisfied,display the ascii chracters
(take user input)

num=int(input("enter the number"))


if 45<=num<=200 and num%4==0 and num%5==0:
print(chr(num))

# [Link] to checking if a string contains a substring

string="hello world"
sub_string="world"

if sub_string in string:
print("yes its present")

#[Link] the maximum value and minimum value in a list

l1=[1,5,3,9,12]

print(max(l1)) #----->12
print(min(l1)) #----->1

#[Link] the index of the maximum value in a list

l2=[1,5,3,9,2]
b=[Link](max(l2))
print(b)

#[Link] duplicates from a list

l3=[11,12,1,31,31,"hero","hero"]
print(set(l3))

#[Link] occurrence of an item in a list

l4=[1,2,3,4,2,2,2,7,8,5]

s=[Link](2)
print(s)

# [Link] if all elements in a list are unique

assignment question

# [Link] to check whether a character is in the alphabet or not,if it is


alphabet,store the value inside a dict(key as a character and value as a ascii
value)

assignment question

# [Link] to check whether a character is in uppercase or not,if uppercase,convert


to lower case and store the value inside the dictionary (character as key and ascii
as value) take user input

assignment question

You might also like