Question

In: Computer Science

Hands-On Assignments are designed to foster independent thinking and problem solving programming skills. This activity is...

Hands-On Assignments are designed to foster independent thinking and problem solving programming skills. This activity is closely guided by the course instructor. Students are encourages to ask instructor any questions related to this challenge. Similar to the course Exercises, this activity also has a Base Code.

The initially given Base Code to Start with this exercise:

--------------Start----------------

guess.py   (also, see starters in the course FILES/StudentFiles/Exercise Starter Files)

--------------End ----------------

Prompt

Task to Accomplish

  1. The Base Code implements “guessing” of one number. You need to add “OUTER” loop that allows “guessing” of 5 numbers of the lottery winning ticket.
  2. Limit numbers of attempts for guessing one number to 10 for each of 5 numbers of the lottery.
  3. Also, you will need to store all 5 randomly generated numbers in separate variables, and print out WINNING NUMBERS at the end, when user finishes guessing of the very last 5th number.

Tips:

You will need to use “nested loops”

Some useful resources:

https://www.tutorialspoint.com/python/python_nested_loops.htm (Links to an external site.)

https://www.quora.com/What-are-the-best-examples-of-a-Nested-Loops-for-Python (Links to an external site.)

https://www.youtube.com/watch?v=HfzCpDilEVM

Solutions

Expert Solution

Here is the complete code for the following code, To make it simple i have taken a lottery number between 1 to 20, you change it to other values as well

Code:

import  random

#we are limiting the range from 1 to 20
#generating 5 random numbers between 1 to 20
lottery_number = random.sample(range(1, 20), 5)
chances_per_lottery = 10
guessing_num = 0

correct_guesses = []  #this list contain the correct numbers guess by user
correct_guesses_count = 0

#outer loop
for number in lottery_number:
    guessing_num = guessing_num + 1
    print("Guessing lottery: ", guessing_num)
    #inner loop
    while(chances_per_lottery > 0):
        print("Remaining chances left: ",  chances_per_lottery)
        num = input("Guess lottery number: ")
        if num == number:
            correct_guesses.append(num)
            correct_guesses_count = correct_guesses_count + 1
            print()
            break
        chances_per_lottery = chances_per_lottery - 1
        if chances_per_lottery == 0  and guessing_num != 5:
            print("Chances Over, Now try to guess the next number\n")
    chances_per_lottery = 10

print("Total correct guesses: ", correct_guesses_count)
print("Numbers are: ", correct_guesses)




Output:

Output:

I have set the guess count 2 but asked for 10 because i do not want very long output. However i have changed this value in code. So just copy and run it


Related Solutions

Background Hands-On Assignments are designed to foster independent thinking and problem solving programming skills. This activity...
Background Hands-On Assignments are designed to foster independent thinking and problem solving programming skills. This activity is closely guided by the course instructor. Students are encourages to ask instructor any questions related to this challenge. Similar to the course Exercises, this activity also has a Base Code. The initially given Base Code to Start with this assignment: This assignment is based on the project 6.9 of the course book. --------------Start---------------- buttondemo.py      breezypythongui.py --------------End ---------------- --------------------------------------- Prompt Task to Accomplish...
1. List 4 skills that include creative thinking and problem solving: 2. List the stages of...
1. List 4 skills that include creative thinking and problem solving: 2. List the stages of a research process 3. Example of evidence of causality: a) Temporal sequence b) Nonspurious association c) A and B d) None of the above
Applying the 21 Synectics Steps The need for thinking and problem-solving skills dominates our lives. Individuals...
Applying the 21 Synectics Steps The need for thinking and problem-solving skills dominates our lives. Individuals must analyze problems in the workplace, at school, as a parent, and in many other daily situations. You have an opportunity to practice your problem-solving skills through this assignment. Assignment: Select one problem from the following list or define your own problem. Design a new textbook for a psychology class, science class, etc. Invent a new telephone. Design a new suitcase. Design new clothes...
Job postings often state that the successful applicant must have superior critical thinking and problem-solving skills....
Job postings often state that the successful applicant must have superior critical thinking and problem-solving skills. Yet employers tell college administrators that graduates, both from undergraduate and graduate programs, often lack these skills. Having read this week's assigned materials, how would you define critical thinking? Why are employers making these comments? Are they justified? Your response should be at least 250 words.
Discuss differences in brain activity associated with solving a problem by insight and solving a problem...
Discuss differences in brain activity associated with solving a problem by insight and solving a problem through step-by-step analysis.
Discuss differences in brain activity associated with solving problem by insight and solving a problem through...
Discuss differences in brain activity associated with solving problem by insight and solving a problem through step-by-step analysis.
This problem will give you hands-on practice with the following programming concepts: • All programming structures...
This problem will give you hands-on practice with the following programming concepts: • All programming structures (Sequential, Decision, and Repetition) • Methods • Random Number Generation (RNG) Create a Java program that teaches people how to multiply single-digit numbers. Your program will generate two random single-digit numbers and wrap them into a multiplication question. The program will provide random feedback messages. The random questions keep generated until the user exits the program by typing (-1). For this problem, multiple methods...
Summarize the strategic hands for problem-solving, and give an example of the meaning of each one...
Summarize the strategic hands for problem-solving, and give an example of the meaning of each one which of the following best summarizes the strategic hand there may be more than one strategy and provide an example of the meaning A there may be several strategies to solving the problem, however only one of them will find the correct answer. For example, there is more than one strategy to stop exit squared plus 3X +2 = 0 however, only one of...
Task: Apply mathematical problem solving skills to a variety of problems at the college level. To...
Task: Apply mathematical problem solving skills to a variety of problems at the college level. To accomplish this task, the students will 1. Identify what they are given and what they need to find; 2. Identify the type of problem they have been given and the tools necessary to solve the problem; 3. Correctly apply the tools to the information given to set up the problem; 4. Perform mathematically correct calculations to determine a solution; 5. Interpret their results in...
In nearly every career sector, problem-solving is one of the key skills that employers seek in...
In nearly every career sector, problem-solving is one of the key skills that employers seek in job applicants. Having good, strong problem solving skills can make a huge difference to your career. Discuss the basic steps of problem solving with example Ecom201 Pleassssse solve your personal solution and do not copy
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT