234k views
5 votes
The conversion depends on the temperature and other factors, but an approximation is that 1inch of rain is equivalent to 6.5inches of snow. Write a script that prompts the user for the number of inches of rain, calls a function to return the equivalent amount of snow, and prints this result. Write the function, as well. Do this two ways: in a separate code file and as a local function.

1 Answer

3 votes

Answer:

rainInches = int(input("Enter rainfall in inches: "))

def rain_snow_convert( rain):

snow_size = rain * 6.5

return snw_size

snowInches = rain_snow_convert( rainInches)

print(snowInches)

Step-by-step explanation:

The python source code above return the equivalent size of rainfall to snowfall in inches. There are two ways to write this, one is like on a single file as the code above, the second way is defining the function "rain_snow_convert" in another python file, then importing and calling the function in the input file.

from functionsfile import rain_snow_convert

rainInches = int(input("Enter rainfall in inches: "))

snowInches = rain_snow_convert( rainInches)

print(snowInches)

where "functionfiles" (actually with the extension .py) is the name of the python file with the rain_snow_convert function.

User Asim Jalis
by
5.0k points