Premium Only Content

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))
-
28:39
Afshin Rattansi's Going Underground
1 day agoDonald Trump’s Gaza Peace Plan: A Pivotal Moment or Farce? (Palestinian Deputy Foreign Minister)
12K5 -
3:31:29
SavageJayGatsby
4 hours ago🔥 Spicy Saturday – Let's Play: Prison Life 2🔥
20.5K1 -
4:34:18
cosmicvandenim
11 hours agoCOSMIC VAN DENIM | WARZONE HORROR
3.03K1 -
29:09
Stephen Gardner
8 hours ago🚨Trump DECLARES WAR on TERRORIST LEFT!
19.1K40 -
LIVE
NellieBean
3 hours ago🔴 Lost Girl looks for Lost Village
80 watching -
30:07
JohnXSantos
1 day agoWhy Clothing Brands NEVER Fail- Master Class
3.09K -
LIVE
Spartan
2 hours agoOMiT Spartan | God of War Ragnarok, College Halo match @ 9:30 EST, then ranked or more GoW:R
5 watching -
LIVE
John_Goetz
2 hours agoJohn Gets Gaming - Ghost of Yotei
4 watching -
AgnoLand
3 hours ago[LIVE] Battlefield 6 | Full Focus, Cinematic Moments, Zero Fear 😎
660 -
24:34
HaileyJulia
8 days agoThis Christian Morning Routine Changed Everything for Me
4K3