Conditionals - Advanced |Section 3|Celestial Warrior
In one of the previous exercises we created the following function:
def string_length(mystring):
return len(mystring)
Calling the function with a string as the value for the argument mystringwill return the length of that string.
However, if an integer is passed as an argument value:
string_length(10)
that wouldgenerate an error since the len() function doesn't work for integers.
Your duty is to modify the function so that if an integer is passed as an input, the function should output a message like "Sorry integers don't have length".
def string_length(mystring):
if type(mystring) == int:
return "Sorry, integers don't have length"
else:
return len(mystring)
The function that we implemented in the previous exercise checks integer datatypes, but not about floats. So, please expand the conditional block so that floats are counted too.
def string_length(mystring):
if type(mystring) == int:
return "Sorry, integers don't have length"
elif type(mystring) == float:
return "Sorry, floats don't have length"
else:
return len(mystring)
In one of the previous exercisesyou created a function that convertedCelsius degrees to Fahrenheit:
def cel_to_fahr(c):
f = c * 9/5 + 32
return f
Now, the lowest possibletemperature that physicalmatter can reach is -273.15C.With that in mind, please improve the function by making itprint out a message in case a number lower than -273.15 is passed as input when calling the function.
def c_to_f(c):
if c< -273.15:
return "That temperature doesn't make sense!"
else:
f=c*9/5+32
return f
print(c_to_f(-273.4))
-
1:31:55
Kim Iversen
11 hours agoTHIRD Trump Assassination Attempt Thwarted?!? | Ballot Glitches, Voters Turned Away By Cops, What's Going On?!?
105K120 -
1:26:31
Donald Trump Jr.
15 hours agoWe’re Just Days Away From Election Day & our MAGA Moment, Plus Interview with Sen Tom Cotton | TRIGGERED Ep.187
152K135 -
2:37:52
Laura Loomer
10 hours agoEP88: LIVE COVERAGE: Trump Rally in Henderson, NV
81K25 -
2:27:28
Slightly Offensive
10 hours ago $54.29 earnedJD Vance Did What?! BOMBSHELL Joe Rogan Interview EXPOSES ALL | Guest: Australian Talk
71K34 -
51:08
Kimberly Guilfoyle
14 hours agoGarbage Politics: Dems Lose Control, Live with Sage Steele, Asm Bill Essayli & Karoline Leavitt | Ep. 170
112K40 -
1:32:03
Glenn Greenwald
13 hours agoVoices For Gaza: Speaking Out Against Israel's Atrocities
78.1K55 -
40:56
TheTapeLibrary
20 hours ago $8.35 earnedThe Disturbing Mystery of the Sudbrink Phone Calls
49.3K12 -
47:58
Chrissy Clark
18 hours agoWashington Post Melt Down, RIGGED Mock Election, & MORE w/ Titus Ellis Smith I Underreported Stories
44.7K12 -
1:47:51
Redacted News
13 hours agoBREAKING! VOTING MACHINE PASSWORDS LEAKED BY DEMOCRATS, BILL CLINTON SLAMS KAMALA'S ECONOMY
157K329 -
1:02:19
In The Litter Box w/ Jewels & Catturd
1 day agoDUMPSTER FIRE | In the Litter Box w/ Jewels & Catturd – Ep. 681 – 10/31/2024
106K83