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))
-
9:09
JonesN420
1 year agoHow Many Levels Can I Get in 1 MATCH.. | Combat Warriors
3 -
1:00
OcoKnight Gaming
3 years agoHollow Knight - Radiant Soul Warrior
39 -
1:08:28
Bad Gaming, Old Lady style!
1 year ago $0.06 earnedTuesday Take Wrath Warrior Leveling Part 5!
2243 -
2:10:54
Hevel Gaming
6 months agoHevel - WoW Classic Hardcore Leveling 22+ Warrior
209 -
4:10
Steel Warrior band
1 year agoThe Crown - Steel Warrior
7 -
1:54:19
Father Russell
1 year agoThe Swordsman X: Survival | Tier 6 Levelling
183 -
1:25:34
Didi
1 year agoHorizon Forbidden West Part 48 - Armor Competition
4 -
1:13:11
Hevel Gaming
6 months agoHevel - WoW Classic Hardcore Warrior 7th Try Level 17+
99 -
33:04
samespiritgaming
10 months agoGot a MAJOR Sword and Shield Upgrade in A Knight's Quest
-
1:37:42
GamesVonJames
7 months agoProject Ascension Season 8: Chapter 4 | Classless World of Warcraft | Edge of Fury
5