Professional Documents
Culture Documents
1. STRING FORMATTING
# STRING FORMATTING
print("The cost of mobile is {:.2f} $".format(30000))
print("The temperature is between {} and {} celcious".format(5,100,200))
print("The temperature is between {:-} and {:+} celcious".format(-5,10))
print("The cost of mobile is {:,} ruppes".format(1000000))
print("I have {:d} mobiles".format(0b111))
print("I have {:d} chocolates".format(0o110))
print("I have {:d} pens".format(0x0112))
print("I have {:o} laptops".format(0b1100))
# Using < to
print("I have {:<} notebooks".format(100))
print("I have {:<10} notebooks".format(100))
print("I have {:>15} notebooks".format(100))
print("I have {:^15} notebooks".format(100))
note,pen,pencil=20,10,5
print("I have {0} notebooks, {1} pens, {2} pencils".format(note,pen,pencil))
print(f"I have {note} {pen} {pencil}")
OUTPUT
listOfNumbers=list(map(int,input("Enter the Numbers: ").split()))
print(len(listOfNumbers))
OUTPUT
3. COUNTING ODD AND EVEN INTEGERS
# FOR LOOP
listOfNumbers=list(map(int,input("Enter the Numbers: ").split()))
count=0
for i in listOfNumbers:
if i%2==0:
count+=1
print("No of Even Integer is {}".format(count))
print("No of Odd Integers is {}".format(len(listOfNumbers)-count))
print()
# SHORT CUT
print(f"The No of Even number is {len([i for i in listOfNumbers if i%2==0])}")
print(f"The No of Even number is {len([i for i in listOfNumbers if i%2!=0])}")
OUTPUT