Lab Quiz 1 GF01 Solution
Lab Quiz 1 GF01 Solution
Output example
Enter the temperature in Celsius: 10
The temperature in Celsius is 10 degrees Celsius
The temperature in Fahrenheit is 50 degrees Fahrenheit
def ConvertToFahrenheit(TempCelsius):
TempFahrenheit = (TempCelsius * 9/5) + 32
return TempFahrenheit
# Main program
TempCelsius = float(input("Enter the temperature in Celsius: "))
print(f"The temperature in Celsius is {TempCelsius} degrees Celsius")
TempFahrenheit = ConvertToFahrenheit(TempCelsius)
print(f"The temperature in Fahrenheit is {TempFahrenheit} degrees Fahrenheit")
1|2
Task#2 (4 points)
Write a void function Print_Odd() that:
▪ Takes one parameter N and prints odd numbers from 1 to N (3 marks).
▪ In the main program ask the user to enter the number N (line 1 in the output example below)
and call Print_Odd() to print the odd numbers from 1 to N (1 mark).
Output example
Enter number: 10
The odd numbers from 1 to 10 are: 1 3 5 7 9
def Print_Odd(N):
print(f"The odd numbers from 1 to {N} are:", end=" ")
for i in range(1, N+1):
if i % 2 != 0:
print(i, end=" ")
print() # for newline
# Main program
N = int(input("Enter number: "))
Print_Odd(N)
2|2