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))
-
LIVE
Due Dissidence
5 hours agoGaza STARVATION Hits Tipping Point, Flotilla CAPTURED, Bongino BREAKS SILENCE, Maxwell MEETS DOJ,
1,285 watching -
26:54
Eat Sleep Cruise
2 days agoWe Tested The 10 Best Cruises for Couples - Here's How They Rank!
111 -
33:05
CarlCrusher
1 day agoLand of the Giants | Return to the Sacred Spirit Canyon - Ep 1
4354 -
26:37
Fat Lip Collective
11 days agoHow I Designed 3D-Printed Mods for My Vintage Toyota KE25
3 -
18:04
LivingontheEmeraldCoastFlorida
14 days agoFREEPORT, FLORIDA! PROS AND CONS | The ULTIMATE moving guide! Full VLOG tour
9 -
30:38
sewgarage
5 days agoGOLF MK2 dashboard upholstery process
22 -
1:20:22
The Heidi St. John Podcast
4 days agoThe Recent Rise of Antisemitism with Rob McCoy
2.24K -
28:31
Sherwood.tv
8 days agoWhat Your Skin Tags Might Be Telling You
1.17K1 -
1:13:58
Sarah Westall
3 hours agoTimes are Changing: Big Pharma Gatekeepers Destroy Competition when they CAN w/ Kevin Trudeau
11.8K5 -
13:51
Colion Noir
5 hours agoDid the SIG P320 Just Kill a U.S. Airman Without Anyone Pulling the Trigger?
42.4K44