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))
-
14:22
Robbi On The Record
2 days ago $0.64 earnedGen Z’s Narcissism Obsession: Why Everyone’s a “Psychologist”
19K9 -
LIVE
GritsGG
6 hours agoQuad Win Streaks!🫡 Most Wins in WORLD! 3600+
256 watching -
1:09:28
Sarah Westall
3 hours agoCan the World Be This Strange? The Nature of Our Reality w/ Darius J Wright
20.7K1 -
1:58:20
megimu32
3 hours agoOn The Subject: Friends | 31 Years of the Sitcom That Defined a Generation
27.1K4 -
30:00
BEK TV
1 day agoCounter Culture Mom
5.04K -
1:24:54
Kim Iversen
6 hours agoTylenol vs Vaccines: Which One Is The REAL Cause Of Autism? The Truth Will Upset You
58.4K67 -
LIVE
GloryJean
4 hours ago2v2 Tuesday 🔥 Night Games w/ The Boys 🖱️ 6.7 K/D
9 watching -
6:14:12
XxXAztecwarrior
6 hours agoNew Season/ War Ablaze
1.79K -
DVR
Armadillofather
3 hours agoTime for some Borderlands Chaos! | Thank you for being here!
1.31K -
1:03:39
TheCrucible
7 hours agoThe Extravaganza! EP: 41 (9/23/25)
282K20