Palindrome with loop
start = 1
end = 40
palindromes = []
for x in range(start , end , 1):
x = str(x)
if x == x[::-1]:
palindromes.append(x)
print(palindromes)
Sort based on length
lst = ["apple" , "orange" , "pineapple" , "kiwi"]
sorted_list = []
while ( len(lst) > 0 ) :
smallest = 0
for i in range(len(lst)) :
if len(lst[i]) < len(lst[smallest]) :
smallest = i
sorted_list.append(lst[smallest])
lst.remove(lst[smallest])
print(sorted_list)
Riddles - Chain of Wisdom
print("question")
answer = input("enter answer : ")
if ( answer == "correct " ) :
print("You guessed it ocrrect")
print("next question ")
answer2 = input("enter answer ; ")
else :
print("incorrect")
Better Chain of Wisdom
import random
question_bank = {
"Three eyes have I, all in a row; when the red one opens, all freeze like the snow." : "Traffic light" ,
"What gets wetter and wetter the more it dries?" : "A towel",
"If you speak its name, you break it. What is it? ":"Silence"
}
questions_list = list(question_bank.keys())
selected_question = random.choice(questions_list)
while True :
print(selected_question)
answer = input("Enter answer : ")
if answer == question_bank[selected_question] :
print('correct')
break
elif answer == "tell me" :
print(question_bank[selected_question])
break
else :
print('incorrect try again')
# random.shuffle(questions_list)
# for i in questions_list:
# print("This is the question:")
# while True :
# print(i)
# answer = input("Enter answer : ")
# if answer == question_bank[i] :
# print('correct')
# break
# elif answer == "tell me" :
# print(question_bank[i])
# break
# else :
# print('incorrect try again')