<jupyter_start><jupyter_text>CSE 110 Week 7 07 Prepare: Checkpoint AssignmentWrite a Python Program that does each of the following:1. Use a while loop to ask the user for a positive number (>= 0). Continue asking as long as the number is negative, then display the number. For example:2. Use a while loop, to simulate a child asking their parent for a piece of candy. Have the program keep looping until the user answers "yes", then have the program output "Thank you." For example: Testing ProcedureVerify that your program works correctly by following each step in this testing procedure:1. For the positive number program, enter several negative numbers, then a positive one.2. Try entering a positive number first, and ensure that it doesn't ask again.3. Try entering 0 and ensure that it correctly treats it as a positive number.4. For the piece of candy program, test your last loop by entering different amounts of no's before finally saying yes.5. Try saying "yes" the very first time, and ensure that it works as expected.<jupyter_code># 01 While Loop
num = int(input("Please type a positive number: "))

while num < 0:
    print("Sorry, that is a negative number. Please try again.")
    num = int(input("Please type a positive number: "))

print(f"The number is: {num}")
# 01 While Loop
yes =  ['yes', 'y']
no = ['no','n']

Q = input("May I have a piece of candy? ")

while Q in no:
    Q = input("May I have a piece of candy? ")
    
print("Thank You!")<jupyter_output>May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? n
May I have a piece of candy? y
Thank You!<jupyter_text>07 Prepare: Team Activity Guess My Number Game AssignmentI. HAVING THE COMPUTER PICK A RANDOM NUMBER CORE REQUIREMENTS1. Start by asking the user for the magic number. (In future steps, we will change this to have the computer generate a random number, but to get started, we'll just let the user decide what it is.)Ask the user for a guess.Using an if statement, determine if the user needs to guess higher or lower next time, or tell them if they guessed it.2. Add a loop that keeps looping as long as the guess does not match the magic number.At this point, the user should be able to keep playing until they get the correct answer.3. Instead of having the user supply the magic number, import the random library and use it to generate a random number from 1 to 100.Play the game and make sure it works!<jupyter_code>import random

number = random.randint(1, 10)
print(number)
# Core Requirement 1
number = int(input("What is the magic number?  "))
guess = int(input("What is your guess?  "))

if guess > number:
    print("Lower")
elif guess < number:
    print("Higher")
else:
    print("You guessed it!")
# Core Requirement 2
number = int(input("What is the magic number?  "))
guess = int(input("What is your guess?  "))

while guess != number:
    if guess > number:
        print("Lower")
        guess = int(input("Guess Again?  "))
    elif guess < number:
        print("Higher")
        guess = int(input("Guess Again?  "))

print("You guessed it!")
# Core Requirement 3
import random

number = random.randint(1, 100)
guess = int(input("Pick a number between 1 and 100:  "))

while guess != number:
    if guess > number:
        print("Lower")
        guess = int(input("Guess Again?  "))
    elif guess < number:
        print("Higher")
        guess = int(input("Guess Again?  "))

print("You guessed it!")
# Stretch Challenge 2
import random

print("Welcome to the Game!")
number = random.randint(1, 5)
guess = int(input("Pick a number between 1 and 100:  "))
count = 0

while guess != number:
    if guess > number:
        print("Lower")
        guess = int(input("Guess Again?  "))
        count += 1 
    elif guess < number:
        print("Higher")
        guess = int(input("Guess Again?  "))
        count += 1 
count += 1

if count == 1:
    word = "try"
word = "try's"

win = (f'''
{"*":*^80}
*{f"It took you {count} {word} to guess it!":^78}*
*{"GAME OVER":^78}*
{"*":*^80}
''')

print(win)
##### Stretch Challenge 3
import random

again = True
yes = ["yes", "y"]
print("Welcome to the Game!\n")

while again == True:
    number = random.randint(1, 5)
    guess = int(input("Pick a number between 1 and 100:  "))
    count = 0

    while guess != number:
        if guess > number:
            print("Lower")
            guess = int(input("Guess Again?  "))
            count += 1 
        elif guess < number:
            print("Higher")
            guess = int(input("Guess Again?  "))
            count += 1 
    count += 1

    if count == 1:
        word = "try"
    word = "try's"

    win = (f'''
    {"*":*^80}
    *{f"It took you {count} {word} to guess it!":^78}*
    *{"GAME OVER":^78}*
    {"*":*^80}
    ''')

    print(win)

    play_again = input("Do you want to play again? (Y/N) ").lower()

    if play_again in yes:
        print(play_again)
        again = True
    else:
        again = False

print(f'''
*** Thanks for Playing! ***
''')<jupyter_output>Welcome to the Game!

Pick a number between 1 and 100:  5
Lower
Guess Again?  3

    ********************************************************************************
    *                       It took you 2 try's to guess it!                       *
    *                                  GAME OVER                                   *
    ********************************************************************************
    
Do you want to play again? (Y/N) y
y
Pick a number between 1 and 100:  4
Lower
Guess Again?  2
Lower
Guess Again?  1

    ********************************************************************************
    *                       It took you 3 try's to guess it!                       *
    *                                  GAME OVER                                   *
    ********************************************************************************
    
Do you want to play again? (Y/N) y
y
Pick a number between 1 and 100:  4
Lower
Guess Again?  3
Lower
Guess Agai[...]
{'fraction_non_alphanumeric': 0.14634146341463414, 'fraction_numerical': 0.016156594686965977, 'mean_word_length': 2.8207715133531157, 'pattern_counts': {'":': 8, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '578132', 'license': 'MIT', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1820, 'n_words': 864, 'path': 'jupyter-notebook-CSE-110/week07.ipynb', 'repo_name': 'vwolfley/cse110-22w-22', 'size': '6437'}