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
SpartakusLIVE
1 hour ago#1 HERO of the PEOPLE || Ending the Week with FUN, WINS, and LAUGHS
123 watching -
LIVE
GritsGG
11 hours agoQuad Win Streaks!🫡 Most Wins in WORLD! 3600+
116 watching -
2:34:12
Spartan
3 hours agoScrims vs Mindfreak and then Ranked or another game idk
4.72K1 -
1:35:57
Roseanne Barr
5 hours agoEnd-Time Prophecies REVEALED: Jonathan Cahn’s Warning
142K54 -
1:08:58
vivafrei
6 hours agoComey INDICTED! Proof Jan. 6 was a FED-SURRECTION! Ostrich Crisis Getting More Attention & MORE!
153K102 -
LIVE
StevieTLIVE
2 hours agoBirthday Bash HYPE Warzone Wins ALL NIGHT
15 watching -
6:30:53
Dr Disrespect
9 hours ago🔴LIVE - DR DISRESPECT - ARENA BREAKOUT: INFINITE - STORM EVENT
181K9 -
3:35:23
Barry Cunningham
9 hours agoPRESIDENT TRUMP SPEAKS ON JAMES COMEY INDICTMENT! MORE TO COME! DELICIOUS LIBERAL MELTDOWNS!
79.3K45 -
25:59
Simply Bitcoin
1 day ago $2.42 earnedMichael Saylor Reveals $81T Bitcoin Plan to Cancel National Debt?!
46K9 -
1:33:51
Steve-O's Wild Ride! Podcast
1 day ago $2.00 earnedJohn C. Reilly's Surprising Connection To Jackass (And Beef With Weeman!)
61.1K11