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))
-
23:23
MYLUNCHBREAK CHANNEL PAGE
11 hours agoThe Sunken Basilica
86.1K8 -
8:05
Hollywood Exposed
2 hours agoCharlie Sheen STUNS Tucker Carlson With His Shocking Political Confession
8.77K16 -
LIVE
SavageJayGatsby
2 hours ago🔥 Spicy Saturday – Let's Play: Prison Life 2🔥
44 watching -
30:02
The White House
3 hours agoVP JD Vance Delivers Remarks at 250th Anniversary Celebration for the United States Marine Corps
16K17 -
3:50:26
GamerGril
6 hours agoShould I Get A Zoob Job 💞Dying Light The Beast💞
15.5K5 -
5:00:18
MattMorseTV
9 hours ago $251.23 earned🔴No Kings "protest" TOTAL CHAOS.🔴
307K496 -
1:28:51
Darkhorse Podcast
7 hours agoCan the internet make you sick? The 297th Evolutionary Lens with Bret Weinstein and Heather Heying
35K10 -
1:21:31
Michael Franzese
20 hours agoTrump Derangement Syndrome Is On The Way Out | Live with Michael Franzese
114K128 -
LIVE
ZWOGs
5 hours ago🔴LIVE IN 1440p! - ARC RAIDERS SERVER SLAM - Come Hang Out!
43 watching -
9:22
Colion Noir
11 hours agoArmed Woman Drags Gunman Out of Store Before Firing Two Shots
93.3K47