Format quiz
a = "powerful"
b = "elegant"
msg = ("Python is {} & {} language and suitable for data analysis").format(a,b)
print(msg)
Python is powerful & elegant language and suitable for data analysis
Length quiz
prog_lang = 'Python'
print(len(prog_lang))
6
Count quiz
#write a program in python to declare a message for an instructing sign in public place
#and get the lenth of that message and count of (o) letter message:
msg = "No Smoking here"
print(len(msg))
msg.count('h')
15
1
msg.count('o')
2
msg.count('s',3,5)
0
msg.count('n')
1
msg.count('N')
1
msg.count('o',7,15)
0
msg.count('o',1,7)
2
msg_1 = "The Python language is wonderful"
msg_2 = "The Python language is elegant"
msg_3 = "The Python language is poweful"
msg_4 = "The Python language is suitable for data analysis"
msg_1.count('w')
1
msg_2.count('e')
4
msg_3.count('l')
2
msg_4.count('i')
3
quiz count 2
job_des = " are you working as a Python programmer?"
job_des_vowel_lower_count = job_des.count('a') + job_des.count('i') +job_des.count('o')+job_des.count('u')+job_des.count('e')
job_des_vowel_upper_count = job_des.count('A')+job_des.count('E')+job_des.count('O')+job_des.count('U')+job_des.count('I')
job_des_vowel_count = job_des_vowel_lower_count + job_des_vowel_upper_count
print(job_des_vowel_count)
12
endswith & startswith quiz
msg_1.endswith('l')
True
msg_1.startswith('T')
True
msg_2.endswith('l')
False
msg_2.startswith('T')
True
msg_3.endswith('l')
True
msg_3.startswith('T')
True
msg_4.endswith('l')
False
msg_4.startswith('T')
True
islower & isupper quiz
msg = "Don't turn left"
msg.isupper()
False
msg.islower()
False
"Don't turn left".upper()
"DON'T TURN LEFT"
"Don't turn left".lower()
"don't turn left"
msg.upper()
"DON'T TURN LEFT"
msg.lower()
"don't turn left"
find quiz
string = "Don't turn left!"
string.find('!')
15
string.index('!')
15
string = "Don't turn left!"
string.find('m')
-1
string = "Don't turn left!"
string.index('m')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-68-9c6571c8eac9> in <module>
1 string = "Don't turn left!"
----> 2 string.index('m')
ValueError: substring not foundreplace & strip quiz
phrase = "The coding is fun"
phrase = phrase.replace('fun','awesome')
phrase.strip('The')
' coding is awesom'
input quiz
name = input('your_name')
your_name Sara
car_color = input('car_color')
car_color red
car_num = input("your_car_plate_number")
your_car_plate_number 123456789Sara
print("name is"+name+","+"car color is"+car_color+","+"car_plate_number is"+ car_num)
name is Sara,car color is red,car_plate_number is 123456789Sara