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))
-
1:33:32
Flyover Conservatives
1 day ago3 Winning Mindsets for Building Life-Changing Habits - Clay Clark; Why Employers Are Ditching DEI - Andrew Crapuchettes | FOC Show
42.5K -
4:04:15
SynthTrax & DJ Cheezus Livestreams
1 day agoFriday Night Synthwave 80s 90s Electronica and more DJ MIX Livestream POST DISCO / FUNK / R & B Edition
41K1 -
51:18
Degenerate Jay
16 hours ago $2.53 earnedJournalist Claims Batman Is A Fascist Like Donald Trump
37.3K8 -
1:18:27
Glenn Greenwald
12 hours agoGlenn Takes Your Questions on Major Saudi Arabia Celeb Controversies, Zohran Mamdani and the NYC Debate, Anti-ICE Protests, and More | SYSTEM UPDATE #533
131K35 -
1:13:26
Tundra Tactical
13 hours ago $5.05 earned🛑{LIVE NOW} Gun Nerd Plays Battlefield 6 Great Tundra Nation Get Together Day 4
30K1 -
12:25:00
GritsGG
12 hours agoRanked Top 70! Most Wins in WORLD! 3734+!
33.9K -
14:41:39
LFA TV
1 day agoLIVE & BREAKING NEWS! | FRIDAY 10/17/25
215K50 -
2:18:18
Joker Effect
6 hours agoRUMBLE COMMUNITY STREAMING NEWS - CA BANS STAKE - ARC RAIDERS - KICK LOYALS TURNING! - NEW X ALGO
12.1K1 -
1:04:41
BonginoReport
11 hours agoMichelle Obama Admits Affirmative Action Is A Scam - Nightly Scroll w/ Hayley Caronia (Ep.158)
110K70 -
1:11:40
Kim Iversen
11 hours agoZelensky BLINDSIDED By Trump In White House Meeting | UK Bans RACIST JEWS From Attending Soccer Match
107K242