0% found this document useful (0 votes)
18 views2 pages

Lab Quiz 1 GF01 Solution

This document outlines Lab Quiz#1 for the course Introduction to Programming (COMP105), scheduled for March 19, 2025. It includes two tasks: the first requires writing a function to convert Celsius to Fahrenheit, and the second involves creating a function to print odd numbers up to a given number N. Each task specifies the requirements and provides example outputs for clarity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Lab Quiz 1 GF01 Solution

This document outlines Lab Quiz#1 for the course Introduction to Programming (COMP105), scheduled for March 19, 2025. It includes two tasks: the first requires writing a function to convert Celsius to Fahrenheit, and the second involves creating a function to print odd numbers up to a given number N. Each task specifies the requirements and provides example outputs for clarity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab Quiz#1 Course Name: Introduction to programming (COMP105)

Term: 2 Track: College of Engineering Track


Duration: 40 minutes
Date: Wednesday, March 19, 2025
10:00 AM: 10:40 AM
Name: ………………………………………………… ID:…………………… Group: GF01 and F1
Mark
…/7
Task#1 (3 points)
Write a user-defined function called ConvertToFahrenheit( ) that:
▪ Takes one parameter: TempCelsius (0.5 mark).
▪ Converts the temperature from Celsius to Fahrenheit using the following formula (0.5 mark):

TempFahrenheit =(TempCelsius × 9/5)+32


▪ Returns the temperature in Fahrenheit (0.5 mark).
▪ In the main program ask the user to enter the temperature in Celsius (line 1 in the output example
below) and print it (line 2 in the output example below) (0.5 mark).
▪ Call ConvertToFahrenheit( ) to convert the temperature and display it (line 3 in the output
example below) (1 mark).

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

You might also like