3.7
Hack 1
Test out the examples above and change up the the starting values to play with how the conditions within each other work. Demonstrate knowledge of nested conditionals by creating your own nested conditional statements.
# Defining a function that takes an integer parameter, `latency`
def check_latency(latency):
# Check if latency is more than 30 Mbps
if latency > 30:
# Check if latency is more than 50 Mbps
if latency > 50:
# Check if latency is more than 100 Mbps
if latency > 100:
return "You have potato internet."
else:
return "You can play Among Us with friends!."
else:
return "You can play Minecraft with friends!"
else:
return "You can play COD with friends!"
# Call the function with value of user's input
print(check_latency(int(input("What is your latency in Mbps?"))))
You have potato internet.
Extra Credit: Caesar Cipher
# Defining a function that takes two paramenters, a string and an integer
def caesar(string, shift):
# Preset alphabet for reference
alphabet = "abcdefghijklmnopqrstuvwxyz"
# Output
new_string = ""
# Looping through given string's characters
for character in string:
# If the character is a letter...
if character.lower() in alphabet:
# Add the shifted character to the new string
index = alphabet.index(character.lower())
new_index = index + (shift % 26)
new_string += (alphabet*2)[new_index]
# Otherwise...
else:
# Add the normal character to the new string
new_string += character
# Return the new string
return new_string
# Call the function with values from user input
print(caesar(input(), -11))
wtaad bn cpbt xh ppsx qwpi