Class IX python Practical
Class IX python Practical
11. Write the Python code for swapping values using third variable.
x=int(input(“Enter the first number”))
y=int(input(“Enter the second number”))
print(“The value of x before swapping”)
print(“The value of y before swapping”)
z=x
x=y
y=z
print(“The value of x after swapping is :“,x)
print(“The value of y after swapping is :”,y)
13. Write a program to calculate sum of numbers till number given by the
user
num=int(input(“Enter any number “))
i=1
sum=0
while (i < num):
sum=sum+ i
i=i+1
print(“Sum of the numbers is “,sum)
15. Write a program to display the name of the city with its temperature
value.
city=['Delhi','Mumbai','KolKata','Chennai']
temp=[43,36,42,38]
search=input('enter the name of the city')
find = -1
for x in range(0,len(city)):
if city[x]==search:
pos=x
temp=temp[x]
find=1
if find==-1:
print("City not found")
else:
print("temperature of ",city[pos], ' in ',temp)