Created
December 1, 2016 13:35
-
-
Save MorkHub/8869bea8ac0f74ab84860316196c96e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sum = 0 # start sum at 0 | |
count = 0 # start count at 0 | |
number = float(input("Enter a number: ")) # get first number | |
while number != 0: # forever if number is not zero | |
sum += number # add number to the sum | |
count += 1 # count the number | |
number = float(input("Enter a number")) # get next number | |
print("Choose an option:"); | |
print("[1] Count values") | |
print("[2] Sum values") | |
print("[3] Average") | |
print("[0] Exit") | |
while True: # forever | |
select = input(" Choose a value: ") # get option | |
if select == '1': # if count | |
print("Count ==", count) | |
elif select == '2': # if sum | |
print("Sum ==",sum) | |
elif select == '3': # if average | |
print("Avg ==",round(sum/count,3)) # calculate, round to 3 decimal places, and print the average | |
elif select == '0': # if exit | |
break # break out of the while True loop | |
else: # the user chose an option that is not valid | |
print("Invalid option, try again.") | |
inp = input("Enter a word/phrase:") # get word/phrase | |
accepted = 'abcdefghijklmnopqrstuvwxyz' # only allow these characters | |
used = '' # no letter has been used yet | |
for char in inp.lower(): # make the word or phrase all lowercase, then get each character | |
if char in accepted and not char in used: # if the current character is allowed, and hasn't been used yet | |
used += str(char) # add the character to used string | |
if len(used) >= 26: # if 26 letters have been used, then it's a pangram | |
print(inp, "is a pangram") | |
else: # if less than 26, then not a pangram | |
print(inp, "is not a pangram") | |
word = input("Enter a word: ").lower() # get a lowercase word | |
if word == word[::-1]: # if the word is the same as it is backwards | |
# word[::-1] means get all of the string called word, but go from the end to the beginning) | |
print(word, "is a palindrome") | |
else: # if the word is different to itself backwards, it is not a palindrome | |
print(word, "is not a palindrome") | |
# same as above but this time we ignore all the characters that aren't letters | |
accepted = 'abcdefghijklmnopqrstuvwxyz' # characters that are allowed | |
word = input("Enter a word: ").lower() | |
word2 = "" # we will store the users string here without any spaces or punctuation etc | |
for i in word: # look at every character | |
if i in accepted: # is it a letter? | |
word2 += i # if it is, add it to word2 | |
if word2 == word2[::-1]: # is it a palindrome | |
print(word, "is a palindrome") | |
else: # if it's not a palindrome | |
print(word, "is not a palindrome") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment