Aug Day 3

Whiteboard Images

Warmup Warmup Whiteboard

Counting Dice Rolls Counting Dice Rolls whiteboard

Code Sections

Warmup Count count = 0
while(count < 100):
    print(count)
    count = count + 5

Counting Dice Rolls # Courtesy of Sarah
# COUNTING DICE ROLLS

import random
one = 0
two = 0
three = 0
four = 0
five = 0
six = 0
count = 0
limit = input("Number of Dice Rolls: ")
limit = int(limit)

while(count < limit):
    dice = random.randint(1, 6)
    if(dice == 1):
        one = one + 1
    elif(dice == 2):
        two = two + 1
    elif(dice == 3):
        three = three + 1
    elif(dice == 4):
        four = four + 1
    elif(dice == 5):
        five = five + 1
    else:
        six = six + 1
    count = count + 1

one = str(one)
two = str(two)
three = str(three)
four = str(four)
five = str(five)
six = str(six)

print("One: " + one)
print("Two: " + two)
print("Three: " + three)
print("Four: " + four)
print("Five: " + five)
print("Six: " + six)

Number Guessing Game ## Courtesy of Ishan
# BASIC CODE

import random

number = random.randint(1, 10)
guess = input("Guess a number: ")
guess = int(guess)

if (guess < number):
    print("Too low.")
elif (guess > number):
    print("Too high.")
else:
    print("You got it!")


# FINISHED CODE

import random

number = random.randint(1, 10)
count = 0
limit = 5

while (count < limit):
    guess = input("Guess a number: ")
    guess = int(guess)
    count = count + 1
    
    if (guess < number):
        print("Too low.")
    elif (guess > number):
        print("Too high.")
    else:
        count = str(count)
        print("You got it in " + count + " guesses!")
        break
    print()

if (guess != number):
    number = str(number)
    print("You ran out of guesses.")
    print("The number was " + number + ".")


# CHALLENGES
# 1. Use a while loop to keep asking for a number if the user's guess is too high.
# 2. Use a while loop to restart the game when the user wins or loses, or ask them if they want to play again.
# 3. Add an "evil number" that increases the guess count by 2 if guessed.

Memory Game from replit import clear
import time
from random import randint

playing = True
string = ""
rounds = 1
while playing:
        num = randint(1, 9)
        string = string + str(num)
        print(string)
        time.sleep(5)
        clear()
        user = input("Please input the string shown previously")
        if(user == string):
                print("Correct, continuing!")
                rounds = rounds + 1
        else:
                print("Incorrect! The string was", string)
                playing = False
print("You got through", rounds, "rounds!")