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))
-
Man in America
8 hours agoLIVE: Assassin Story DOESN'T ADD UP! What Are They HIDING From Us?? | LET'S TALK
27.5K21 -
2:24:17
Barry Cunningham
4 hours agoFOR PRESIDENT TRUMP WILL TAKE NO PRISONERS AND THE LIBS SHOULD EXPECT NO MERCY!
69.1K49 -
1:08:41
Savanah Hernandez
5 hours agoCharlie Kirk Was Our Bridge And The Left Burned It
30.2K36 -
1:59:01
Flyover Conservatives
7 hours agoFinancial Web Behind Charlie Kirk's Murder with Mel K | Silver On It's Way to $50 | FOC Show
44.1K2 -
LIVE
We Like Shooting
16 hours ago $0.08 earnedWe Like Shooting 628 (Gun Podcast)
134 watching -
1:09:26
Glenn Greenwald
7 hours agoTrump's Shifting Immigration and H-1B Policies: With Journalist Lee Fang and Political Science Professor Ron Hira | SYSTEM UPDATE #515
164K34 -
13:09:23
LFA TV
1 day agoLFA TV ALL DAY STREAM - MONDAY 9/15/25
253K61 -
54:12
Donald Trump Jr.
6 hours agoCharlie's Vision. Our Future. | TRIGGERED Ep274
197K121 -
1:03:35
BonginoReport
7 hours agoKirk’s Alleged Killer Dating Hateful Transgender??? - Nightly Scroll w/ Hayley Caronia (Ep.134)
126K146 -
1:01:12
The Nick DiPaolo Show Channel
9 hours agoKirk Assassination Exposes Insane Left | The Nick Di Paolo Show #1793
101K26