Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3 Things (wew)
#1
I created an "Are you smarter than a fifth grader" program, and wanted to upload it here. I looked into the programming ideas and challenges thread and found out i already created two years ago. These are:
2) make a program to encrypt/decrypt a string
3) make a word-guess/number-guess game
Here is the program to encrypt/decrypt a string: (May 12, 2016)
import string
import random
import time

possibleChacters = string.ascii_lowercase + string.digits + string.ascii_uppercase + ' .,!?;:'

target = input("Enter your target text: ")
attemptThis = ''.join(random.choice(possibleChacters) for i in range(len(target)))

completed = False

generation = 0

while completed == False:
    print(attemptThis)
    attemptNext = ''
    completed = True
    for i in range(len(target)):
        if attemptThis[i] != target[i]:
            completed = False
            attemptNext += random.choice(possibleChacters)
        else:
            attemptNext += target[i]
    generation += 1
    attemptThis = attemptNext
    time.sleep(0.1)

print("Target matched! That took " + str(generation) + " generation(s)")
Here is a word guess game (you type the color and not the word): (May 15, 2016)
import tkinter
import random

colours = ['Red','Blue','Green','Pink','Black','Yellow','Orange','White','Purple','Brown']
score=0
timeleft=30

def startGame(event):

    if timeleft == 30:
        countdown()
        
    nextColour()

def nextColour():

    global score
    global timeleft

    if timeleft > 0:

        e.focus_set()

        if e.get().lower() == colours[1].lower():
            score += 1

        e.delete(0, tkinter.END)
        random.shuffle(colours)
        label.config(fg=str(colours[1]), text=str(colours[0]))
        scoreLabel.config(text="Score: " + str(score))

def countdown():

    global timeleft

    if timeleft > 0:

        timeleft -= 1
        timeLabel.config(text="Time left: " + str(timeleft))
        timeLabel.after(1000, countdown)
    
root = tkinter.Tk()
root.title("TTCANTW")
root.geometry("375x200")

instructions = tkinter.Label(root, text="Type in the colour of the words, and not the word text!", font=('Helvetica', 12))
instructions.pack()

scoreLabel = tkinter.Label(root, text="Press enter to start", font=('Helvetica', 12))
scoreLabel.pack()

timeLabel = tkinter.Label(root, text="Time left: " + str(timeleft), font=('Helvetica', 12))
timeLabel.pack()

label = tkinter.Label(root, font=('Helvetica', 60))
label.pack()

e = tkinter.Entry(root)
root.bind('<Return>', startGame)
e.pack()
e.focus_set()

root.mainloop()
And finally, Are you smarter than a fifth grader? (only one quiz so far): (June 8, 2018)
import time
import sys
score = 0
hints = 1
print("Welcome! It is time to find out if you are smarter than a fifth grader!")
time.sleep(2)
print("There will be a total of over 70 tests, each with five questions.")
time.sleep(2)
print("You have infinite time per question, but, don't cheat. You can type hint at any time for a hint")
time.sleep(2)
print("A feature will be added where you can start from any question")
time.sleep(2)
print("Question 1: If Olivia hit her funny bone, what joint did she hit? (Level 1)")
console = input('> ')
quiz_1 = True
question_1_1 = True
while quiz_1 == True:

    while question_1_1 == True:

        if console == 'elbow':
            print('Correct!')
            score = score + 1
            print("Question two: True or False: Neon is a metal (Level 3)")
            console = input('> ')
            question_1_1 = False
            question_2_1 = True
        elif console == 'hint':
            print("Hint used.")
            hints = hints - 1
            print("The funny bone is located in the arm")
            console = input('> ')
        else:
            print("I'm sorry, but that is incorrect.")
            print("Question two: True or False: Neon is a metal (Level 3)")
            console = input('> ')
            question_1_1 = False
            question_2_1 = True

    while question_2_1 == True:

        if console == 'false':
            print('Correct!')
            score = score + 1
            print("Question three: What is the official language of austrailia? (Level 4)")
            console = input('> ')
            question_2_1 = False
            question_3_1 = True
        elif console == 'hint':
            test_for_hint = True
            while test_for_hint == True:

                if hints >= 1:
                    print("Hint used.")
                    hints = hints - 1
                    print("Neon is a chemical.")
                    console = input('> ')
                    test_for_hint = False
                else:
                    print("Insufficient amount of hints.")
                    console = input('> ')
                    test_for_hint = False
        else:
            print("I'm sorry, but that is incorrect.")
            print("Question three: What is the official language of austrailia? (Level 4)")
            console = input('> ')
            question_2_1 = False
            question_3_1 = True

    while question_3_1 == True:

        if console == 'english':
            print('Correct!')
            score = score + 1
            print("Question four: What number is exactly halfway between 1 and 7 on a number line (Level 2)")
            console = input('> ')
            question_3_1 = False
            question_4_1 = True
        elif console == 'hint':
            test_for_hint = True
            while test_for_hint == True:

                if hints >= 1:
                    print("Hint used.")
                    hints = hints - 1
                    print("What language do they speak in austrailia?")
                    console = input('> ')
                    test_for_hint = False
                else:
                    print("Insufficient amount of hints.")
                    console = input('> ')
                    test_for_hint = False
        else:
            print("I'm sorry, but that is incorrect.")
            print("Question four: What number is exactly halfway between 1 and 7 on a number line (Level 2)")
            console = input('> ')
            question_3_1 = False
            question_4_1 = True

    while question_4_1 == True:

        if console == '4':
            print('Correct!')
            score = score + 1
            print("Question five: How do you spell the plural of phenomenon (Level 5)")
            console = input('> ')
            question_4_1 = False
            question_5_1 = True
        elif console == 'four':
            print('Correct!')
            score = score + 1
            print("Question five: How do you spell the plural of phenomenon (Level 5)")
            console = input('> ')
            question_4_1 = False
            question_5_1 = True
        elif console == 'hint':
            test_for_hint = True
            while test_for_hint == True:

                if hints >= 1:
                    print("Hint used.")
                    hints = hints - 1
                    print("If 3 is in the middle of 0 and 6 on a number line, what is 1 and 7?")
                    console = input('> ')
                    test_for_hint = False
                else:
                    print("Insufficient amount of hints.")
                    console = input('> ')
                    test_for_hint = False
        else:
            print("I'm sorry, but that is incorrect.")
            print("Question five: How do you spell the plural of phenomenon (Level 5)")
            console = input('> ')
            question_4_1 = False
            question_5_1 = True

    while question_5_1 == True:

        if console == 'phenomena':
            print('Correct!')
            score = score + 1
            print("Congratulations! You scored " + str(score) + " out of 5 points") # Make the message change depending on your score
            time.sleep(1)
            calculate_score = True
            while calculate_score == True:

                if score == 0:
                    print("You scored an F (FAIL)")
                    calculate_score = False
                elif score == 1:
                    print("You scored an F (FAIL)")
                    calculate_score = False
                elif score == 2:
                    print("You scored an F (FAIL)")
                    calculate_score = False
                elif score == 3:
                    print("You scored a D (FAIL)")
                    calculate_score = False
                elif score == 4:
                    print("You scored a B (PASS)")
                    calculate_score = False
                elif score == 5:
                    print("You scored an A+")
                    calculate_score = False
                elif score < 0:
                    print("Error: Score is below an accepted limit. Score is " + str(score) + ".")
                    time.sleep(5)
                    print("Exiting program.")
                    time.sleep(3)
                    sys.exit(0)
                else:
                    print("Error: Score is above an accepted limit. Score is " + str(score) + ".")
                    time.sleep(5)
                    print("Exiting program.")
                    time.sleep(3)
                    sys.exit(0)
            print("This program will exit in 2 minutes.")
            time.sleep(120)
            sys.exit(0)
        elif console == 'hint':
            test_for_hint = True
            while test_for_hint == True:

                if hints >= 1:
                    print("Hint used.")
                    hints = hints - 1
                    print("Similar to octopi, but not exact")
                    console = input('> ')
                    test_for_hint = False
                else:
                    print("Insufficient amount of hints")
                    console = input('> ')
                    test_for_hint = False
        else:
            print("I'm sorry, but that is incorrect.")
            print("Congratulations! You scored " + str(score) + " out of 5 points")
            calculate_score = True
            while calculate_score == True:

                if score == 0:
                    print("You scored an F (FAIL)")
                    calculate_score = False
                elif score == 1:
                    print("You scored an F (FAIL)")
                    calculate_score = False
                elif score == 2:
                    print("You scored an F (FAIL)")
                    calculate_score = False
                elif score == 3:
                    print("You scored a D (FAIL)")
                    calculate_score = False
                elif score == 4:
                    print("You scored a B (FAIL)")
                    calculate_score = False
                elif score >= 5:
                    print("Error: Score is above an accepted limit. Score is " + str(score) + ".")
                    time.sleep(5)
                    print("Exiting program")
                    time.sleep(3)
                    sys.exit(0)
                else:
                    print("Error: Score is below an accepted limit. Score is " + str(score) + ".")
                    time.sleep(5)
                    print("Exiting program")
                    time.sleep(3)
                    sys.exit(0)
            print("This program will exit in 2 minutes.")
            time.sleep(120)
            sys.exit(0)
Self-taught HTML, CSS, Python, and Java programmer
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020