Import Math
Import Math
[ Formula : c/5 = f-32/9 [ where the c = temperature in Celsius and f = temperature in Fahrenheit]
Expected Output :
60°C is 140 in Fahrenheit
45°F is 7 in Celsius Write a Python program to convert temperatures to and from Celsius,
Fahrenheit.
The centigrade scale, which is also called the Celsius scale, was developed by Swedish
astronomer Andres Celsius. In the centigrade scale, water freezes at 0 degrees and boils at 100
degrees. The centigrade to Fahrenheit conversion formula is:
Fahrenheit and centigrade are two temperature scales in use today. The Fahrenheit scale was
developed by the German physicist Daniel Gabriel Fahrenheit . In the Fahrenheit scale, water
freezes at 32 degrees and boils at 212 degrees.
C = (5/9) * (F - 32)
Where F is the Fahrenheit temperature. You can also use this Web page to convert Fahrenheit
temperatures to centigrade. Just enter a Fahrenheit temperature in the text box below, then click
on the Convert button.
temp = input("Input the temperature you like to convert? (e.g., 45F, 102C etc.) : ")
degree = int(temp[:-1])
i_convention = temp[-1]
if i_convention.upper() == "C":
o_convention = "Fahrenheit"
o_convention = "Celsius"
else:
quit()
Output:
2. Write a Python program to guess a number between 1 to 9.
Note : User is prompted to enter a guess. If the user guesses wrong then the prompt appears again until
the guess is correct, on successful guess, user will get a "Well guessed!" message, and the program will
exit
import random
guess_num = int(input('Guess a number between 1 and 10 until you get it right : '))
print('Well guessed!')
Output:
3. Write a Python program to construct the following pattern, using a nested for loop.
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
n=5;
for i in range(n):
for j in range(i):
print('')
for i in range(n,0,-1):
for j in range(i):
print('')
4. Write a Python program to calculate a dog's age in dog's years.
Note: For the first two years, a dog year is equal to 10.5 human years. After that, each dog year equals 4
human years.
Expected Output:
if h_age < 0:
exit()
else:
Output:
Output: