STRING FORMATTING:
--------------------
These are used to infused at a runtime and this can be done in 3 ways.
1.formatting with placeholders
2.formatting with .format()
3.formatting 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,
1.conditional flow control stmt
2.loop flow control stmt
1.conditional 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,
1.simple if
2.if-else
3.elif
4.nested if-else
1.simple 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:------------------------------>
# 1.wap 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}')
#2.wap 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}')
#3.wap 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")
#4.wap 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}')
#5.wap 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")
#6.wap 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")
#7.wap 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")
#8.wap 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")
#9.wap to check if the given number is postive take user input
num=int(input("enter the number"))
if num>0:
print("its postive number")
#10.wap 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")
#11.wap 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")
# # 12.wap to check the given string is uppercase or not (take user input)
a=str(input("enter the character"))
if a.isupper():
print("its uppercase")
#13.wap 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")
#14.wap 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")
#15.wap 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")
#16.wap 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))
#17.wap 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:
l.append(num)
print(l)
#19.wap 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)
#20.wap 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))
# 21.wap to checking if a string contains a substring
string="hello world"
sub_string="world"
if sub_string in string:
print("yes its present")
#22.finding the maximum value and minimum value in a list
l1=[1,5,3,9,12]
print(max(l1)) #----->12
print(min(l1)) #----->1
#23.finding the index of the maximum value in a list
l2=[1,5,3,9,2]
b=l2.index(max(l2))
print(b)
#24.removing duplicates from a list
l3=[11,12,1,31,31,"hero","hero"]
print(set(l3))
#25.counting occurrence of an item in a list
l4=[1,2,3,4,2,2,2,7,8,5]
s=l4.count(2)
print(s)
# 26.checking if all elements in a list are unique
assignment question
# 27.wap 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
# 28.wap 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