11/6/2020 Control Structures - Jupyter Notebook
Program to Convert Fahrenheit to Celsius and
vice versa ¶
Author - Virendra Singh Kushwah
In [1]: print ("This program will convert temeratures (Fahrenheit / Celsius)")
print ("Enter (F) to convert fahrenheit to celsius")
print ("Enter (C) to convert celsius to fahrenheit")
a = input ("Enter Selection: ") # variable to take values F or C
temp = int (input ("Enter temperature to convert: "))
if a == 'F':
converted_temp = (temp-32)*5/9
print (temp, 'degree fahrenheit equal ', converted_temp, 'degree celsius')
else:
converted_temp = (9/5*temp)+32
print (temp, 'degree celsius equal ', converted_temp, 'degree fahrenheit')
This program will convert temeratures (Fahrenheit / Celsius)
Enter (F) to convert fahrenheit to celsius
Enter (C) to convert celsius to fahrenheit
Enter Selection: F
Enter temperature to convert: 89
89 degree fahrenheit equal 31.666666666666668 degree celsius
In [2]: print ("This program will convert temeratures (Fahrenheit / Celsius)")
print ("Enter (F) to convert fahrenheit to celsius")
print ("Enter (C) to convert celsius to fahrenheit")
a = input ("Enter Selection: ") # variable to take values F or C
temp = int (input ("Enter temperature to convert: "))
if a == 'F':
converted_temp = (temp-32)*5/9
print (temp, 'degree fahrenheit equal ', converted_temp, 'degree celsius')
else:
converted_temp = (9/5*temp)+32
print (temp, 'degree celsius equal ', converted_temp, 'degree fahrenheit')
This program will convert temeratures (Fahrenheit / Celsius)
Enter (F) to convert fahrenheit to celsius
Enter (C) to convert celsius to fahrenheit
Enter Selection: C
Enter temperature to convert: 45
45 degree celsius equal 113.0 degree fahrenheit
localhost:8888/notebooks/CSE1021/Control Structures.ipynb# 1/2
11/6/2020 Control Structures - Jupyter Notebook
In [3]: # Program to understand while loop or iteration
sum1 = 0
current = 1
n=int (input("Enter value :"))
while current <= n:
sum1 = sum1 + current
current = current + 1
print ("Sum : ", sum1)
Enter value :9
Sum : 45
In [4]: print ("This program will convert temeratures (Fahrenheit / Celsius)")
print ("Enter (F) to convert fahrenheit to celsius")
print ("Enter (C) to convert celsius to fahrenheit")
a = input ("Enter Selection: ") # variable to take values F or C
# to check the correct input value
while a!='F' and a!='C': # for negate condition you have to put "!=" and its is
a=input ("Please enter 'F or 'C ")
temp = int (input ("Enter temperature to convert: "))
if a == 'F':
converted_temp = (temp-32)*5/9
print (temp, 'degree fahrenheit equal ', converted_temp, 'degree celsius')
else:
converted_temp = (9/5*temp)+32
print (temp, 'degree celsius equal ', converted_temp, 'degree fahrenheit')
This program will convert temeratures (Fahrenheit / Celsius)
Enter (F) to convert fahrenheit to celsius
Enter (C) to convert celsius to fahrenheit
Enter Selection: S
Please enter 'F or 'C D
Please enter 'F or 'C H
Please enter 'F or 'C F
Enter temperature to convert: 75
75 degree fahrenheit equal 23.88888888888889 degree celsius
In [ ]:
localhost:8888/notebooks/CSE1021/Control Structures.ipynb# 2/2