Conditioanal and Itertaitve Stattements
Conditioanal and Itertaitve Stattements
ITERTAITVE
STATTEMENTS
should tell the user that the entry is invalid. Otherwise, the
program should convert the length to inches and print out the
#CODING:
h_inch += h_ft * 12
#OUTPUT:
Feet: 5
Inches: 3
#coding
item = int(input("enter the total number of
item = "))
if item < 10 :
print("total cost = ",item * 120 , "rs")
elif 10 < item and item < 99 :
print("total cost = ",item * 100, "rs")
else :
print("total cost = ",item * 70 , "rs")
#ouput :
#coding:
num1 = int(input("Enter number 1 : "))
num2 = int(input("Enter number 2 : "))
if num1 + 0.01 == num2:
print("close")
elif num2 + 0.01 == num1:
print("close")
else:
print("Not Close")
Output:
Enter number 1 : 15.01
Enter number 2 : 15.02
close
4. A year is a leap year if it is divisible by 4, except
that years divisible by 100 are not leap years unless
they are also divisible by 400. Write a program that
#coding
year = int(input("Enter a year: "))
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
#output:
RESTART: C:/Users/HP/AppData/Local/Programs/Python/Python37-
32/KKKKKKKKK.PYY.py
Enter a year: 2019
2019 is not a leap year
>>>
5. Write a program to input length of three sides of a
#coding
else:
output:
#coding:
A = [1, 2, 3, 4, 5, 6]
print(A)
reverseList(A, 0, 5)
print("Reversed list is")
print(A)
#output :
1 2 3 4 5 6
Reversed array is
6 5 4 3 2 1
2. Ask the user to enter a list of strings. Create a new list that
#coding:
#output:
RESTART:
C:/Users/HP/AppData/Local/Programs/Python/Pyth
on37-32/KKKKKKKKK.PYY.py
enter a list of string:[1,3,5]
['1,3,5]']
TUPLES
1.Write a Python program that creates a tuple
storing first 9 terms of Fibonacci series.
#coding
#output:
Fibonacci sequence upto 10 :
0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21, 34
2. Write a program that inputs two tuples and
creates a third, that contains all elements of the first
followed by all elements of the second.
#OUTPUT
t1=(‘a’,’b’)
t2=(‘c’,’d’)
t3=(‘a’,’b’,’c’,’d’)
DICTIONARIES
1. Given the dictionary x = {‘k1’: ‘v1’, ‘k2’:
‘v2’, ‘k3’: ‘v3’}, create a dictionary with the
opposite mapping i.e., write a program to
create the dictionary as : inverted_x = { ‘
v1’ : ‘ k1’ , ‘ v2 ‘ : ‘ k2 ‘ , ‘ v3 ‘ : ‘ k3 ‘ }
#coding
# output
RESTART:
C:/Users/HP/AppData/Local/Programs/Pyt
hon/Python37-32/KKKKKKKKK.PYY.py
{'V1': 'K1', 'V2': 'K2', 'V3': 'K3'}