Question

In: Computer Science

Problem 1 of 2: GUESSING GAME . prompting for the maximaum number .correctly calculating the difference...

Problem 1 of 2: GUESSING GAME
. prompting for the maximaum number
.correctly calculating the difference & percent difference
.identifying higher or lower
.correctly reporting way too high /low & slightly high /low
.repeat 5 times
.display correct answer to user .
. exit program if they guess the correct answer
.

Problem 2 of 2 : Drawing a Picture
. only use turtle graphics
.at least four different colours
.include colour
.at least one circle
. at least four distinct shapes

Solutions

Expert Solution

Problem 1 of 2: Guessing Game

import random

max_number = int(input("Enter the maximum numbr you want to play the guessing game with.\n"))

number_to_guess = random.randint(0, max_number)

for _ in range(5):
    guessed_number = int(input("Guess a number:\t"))
    
    difference = number_to_guess - guessed_number
    percentage_difference = abs(difference / max_number)
    
    if guessed_number == number_to_guess:
        print("You guessed it right.")
        break
    
    if difference > 0:
        if percentage_difference <= 0.2:
            print("Slightly Lower")
        else:
            print("Way too Low")
    else:
        if percentage_difference <= 0.2:
            print("Slightly Higher")
        else:
            print("Way too High")
else:
    print("The correct number was ", number_to_guess)

The game is to guess a number that the computer has determined randomly withing a given range.

Steps;-

  1. User input for the range within which we will be guessing the number. Storing it in max_number
  2. Using the random.randint function to randomly get a number between the range 0 to max_number
  3. As we have to guess the number withing 5 iterations our loop will run 5 time.
  4. Take the guessed number from the user till he guesses the right number.
  5. If the user has guessed the right number, print the message and break from the loop
  6. If the difference is positive. Then we will check for the Slightly Lower or Way too Low conditions. (20% threshold)
  7. If the difference is negative. Then we will check for the Slightly Higher or Way too High conditions. (20% threshold)
  8. If we are not able to guess the number in 5 turns. The else condition will trigger and print the number to be guessed.

Problem 2 of 2: Drawing a Picture

import turtle

turtle.hideturtle()
turtle.speed(100)
turtle.bgcolor("black")

turtle.backward(400)

#STAR
turtle.color("red")

for i in range(5):
        turtle.forward(100)
        turtle.right(144)

turtle.forward(100)
turtle.color("black")
turtle.forward(50)

#SQUARE
turtle.color("blue")
for i in range(4):
        turtle.forward(100)
        turtle.right(90)

turtle.forward(100)
turtle.color("black")
turtle.forward(50)

#TRIANGLE
turtle.color("green")
for i in range(3):
        turtle.forward(100)
        turtle.left(120)

turtle.forward(100)
turtle.color("black")
turtle.forward(100)

#CIRCLE
turtle.color("yellow")
turtle.circle(50)

turtle.done()

The three-line of code after every for loop is to set the pointer in such a way that it does not overlap.


Related Solutions

guessing game in Java. It will have a guess input used for guessing the random number...
guessing game in Java. It will have a guess input used for guessing the random number that is generated from 1 - 100. When the user makes a guess it will tell them if the number is lower or higher than the guess. There is also a choice to give up which then reveals the correct number. The last choice will be new game which resets the random number. Last, the program should keep counts of tries. When the user...
Write a Java program that implements the Number Guessing Game: 1. First generate a random number...
Write a Java program that implements the Number Guessing Game: 1. First generate a random number (int) between 0 and 100, call it N 2. Read user input (a guess) 3. check the number, if it's smaller than N, output "The number is larger than that" 4. If the input is larger than N, output "The number is smaller than that" 5. If the input is equal to N, output " You got it!", and exit 6. Repeat until the...
Random Number Guessing Game Write a program in C++ that generates a random number between 1...
Random Number Guessing Game Write a program in C++ that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high. Try again.” If the user’s guess is lower than the random number, the program should display “Too low. Try again.” The program should use a loop that repeats until the user correctly guesses the random number....
Part1. Create a number guessing game in Python. Randomly generate a number from 1 to 10....
Part1. Create a number guessing game in Python. Randomly generate a number from 1 to 10. Have the user guess the number. If it is too high, tell the user to guess lower - it it is too low, tell the user to guess higher. Continue until she guesses the correct number. - Part 2. Allow the user to play a new game after they have guessed correctly.   Part 3. Ask for a different name and keep track of how...
1. [100] Create a C program for a number guessing game. Here are the requirements: a....
1. [100] Create a C program for a number guessing game. Here are the requirements: a. Your program generates a random number between -100 and 100 and keeps asking the user to guess the number until the user guesses it correctly. Your random number generator should be implemented as a C function which takes min and max values as input parameters and returns a random number between those values including the min and the max. b. If the user guesses...
Number guessing Game (20 Marks) Write a C program that implements the “guess my number” game....
Number guessing Game Write a C program that implements the “guess my number” game. The computer chooses a random number using the following random generator function srand(time(NULL)); int r = rand() % 100 + 1; that creates a random number between 1 and 100 and puts it in the variable r. (Note that you have to include <time.h>) Then it asks the user to make a guess. Each time the user makes a guess, the program tells the user if...
JAVA Write a number guessing game that will generate a random number between 1and 20 and...
JAVA Write a number guessing game that will generate a random number between 1and 20 and ask the user to guess that number. The application should start by telling the user what the app does. You should then create the random number and prompt the user to guess it. You need to limit the number of times that the user can guess to 10 times. If the user guesses the number, display some message that tell them that they did...
This is for java For my assignment, I was supposed to make a number guessing game....
This is for java For my assignment, I was supposed to make a number guessing game. The class, HiLo, should pick a random number between 1 and 100 (inclusive). Then, prompt the user to guess the number. On each guess, print if the user is correct or if the guess is too high or too low. Allow only 5 guesses. In the end, print out the correct answer and how many attempts were made. Then give the user the option...
Random Number Guessing Game C++. Write a program that generates a random number between 5 and...
Random Number Guessing Game C++. Write a program that generates a random number between 5 and 20 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display Too high. Try again. If the user’s guess is lower than the random number, the program should display Too low, Try again. The program should use a loop that repeats while keeping a count of the number of guesses...
Using pseudocode design a number guessing game program. The program should generate a random number and...
Using pseudocode design a number guessing game program. The program should generate a random number and then ask the user to guess the number. Each time the user enters his or her guess, the program should indicate it was too high or too low. The game is over when the user correctly guesses the number. When the game ends, the program should display the number of guesses that the user made.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT