 # Functions in Python

Hi I am struggling with these directions.

· Declare a function called C_to_F that will prompt the user for a temperature in Celsius, then convert this value to Fahrenheit, and next, display this converted value to the user.

· Declare a function called F_to_C that will prompt the user for a temperature in Fahrenheit, then convert this value to Celsius, and afterward, display this value to the user.

· Declare a function that takes one parameter and generates X random numbers for the user in the range of 1 to 100 (where X is the value sent to the function) This function should also check to ensure that a valid value is sent to the function, and if not, the function should print an error message that is displayed to the user.

· Call each function you created above through lines of code in your .py file that executes each of the above functions once time. Make sure you prompt the user for values for use in the functions calls of the functions you have created.

This is what I have:

def C_to_F ():
c = int(input(“Please enter the temp in Celsius to convert it to Fahrenheit”))
f = c * 9/5 +32
print(“the temeprature {} Celsius is {} Fahrenheit”.format(c,f))

def F_to_C ():
f = int(input(“Please enter the temp in Fahrenheit to convert it to Celsius”))
c = (f-32) * (5/9)
print(“the temperature {} Fahrenheit is {} Celsius”.format(f,c))

C_to_F()
F_to_C()

import random
def genRandom (x):
for i in range(x):
temp = random.randint (1, 100)
print(‘random # x is {}’.format(i + 1, temp))

genRandom()

Hello @system9382687309 , welcome to the forums! Do you have a specific question to ask? Also, in future, make sure you format your code correctly, as of this post.

1 Like