Question

Could you solve the question below with python code? suppose there are two groups of in...

Could you solve the question below with python code?

suppose there are two groups of in a lottery system. A player should pick five numbers from first fifty positive integer numbers. And a second player should picks 1 number from the first 10 positive integer numbers. If a player chose 7, 20, 21, 22, 40 for the first group and 3 for the second group. Please write a function named chose that randomly creates and returns six numbers.

First 5 values shouldn't be repeated. For example, output will be this:

chose()

array([21, 5, 29, 22, 4, 1])

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code is written in python3.

The following code of the program is explained with comments. Please let me know if you have any doubts regarding the code.

Code:

import array

import random

# This function returns an array where first five numbers are between 1 and 50 and the last number is between 1 to 10

def chose():

    # Creating an object of type array where the type of elements is unsigned int with no elements at start

    arr = array.array('i',[])

    # Creating a list of numbers of first 50 natural numbers

    values = [i+1 for i in range(50)]

    # This loop is iterated when the first five random numbers are appened to the array

    while len(arr) < 5:

        # Generating an random value from the values list

        random_value = random.choice(values)

        # If the random_value is not in the arr

        if random_value not in arr:

            # Append it to arr

            arr.append(random_value)

    # Appending an random value from the first 10 natural numbers to the arr

    arr.append(random.choice(values[:10]))

    # Returning the arr

    return arr

# This is the main function

def main():

    # Storing the result of the chose() function

    res = chose()

    # Printing the result of the chose() function

    print(res)

# Calling the main function

main()

Code screenshot:

Sample Output:

Add a comment
Know the answer?
Add Answer to:
Could you solve the question below with python code? suppose there are two groups of in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help with assignment This assignment involves simulating a lottery drawing. In this type of lottery...

    Need help with assignment This assignment involves simulating a lottery drawing. In this type of lottery game, the player picks a set of numbers. A random drawing of numbers is then made, and the player wins if his/her chosen numbers match the drawn numbers (disregarding the order of the numbers). More specifically, a player picks k distinct numbers between 1 and n (inclusive), as well as one bonus number between 1 and m (inclusive). "Distinct" means that none of the...

  • COP2221 - Intermediate C++ Programming Module #6 Assignment One 20 points This assignment refers to Learning...

    COP2221 - Intermediate C++ Programming Module #6 Assignment One 20 points This assignment refers to Learning Outcome #2: Create and utilize arrays to store lists of related data Programming Problem You have been hired to create a C++ program to simulate the lottery. Your program allows users to see how often their lottery number choices match a randomly generated set of numbers used to pick lottery winners. The company, "How Lucky Are You?, Inc." wants a modular, professional and user-friendly...

  • Please help with this, and leave comments explainging the code you wrote, thank you for your...

    Please help with this, and leave comments explainging the code you wrote, thank you for your help Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an array of six integers named lotteryNumbers, and another array of six integers named userLotteryPicks. The class' constructor should use the Random class to generate a unique random number in the range of 1 to 60 for each of the 6 elements in the lotteryNumbers array. Thus, there...

  • Plz i want answer these question using list in python programme. You are given two sequences...

    Plz i want answer these question using list in python programme. You are given two sequences of n integers: 21, 22, ...,an and b1,b2, ..., bn Print a sequence of 2n integers created by alternating elements from the given sequences: a1, 61, 42, 62, a3, 63, ..., an, bn. Input The first line contains a positive integer n (1 <n<1000) - the length of the sequences The second line contains n space-separated integers 01, 02, ..., an (-1000 <a; <...

  • Swapping Values in python Summary In this lab, you complete a Python program that swaps values...

    Swapping Values in python Summary In this lab, you complete a Python program that swaps values stored in three variables and determines maximum and minimum values. The Python file provided for this lab contains the necessary input and output statements. You want to end up with the smallest value stored in the variable named first and the largest value stored in the variable named third. You need to write the statements that compare the values and swap them if appropriate....

  • Please solve only if you know how to do it. Write the code using C++ (not...

    Please solve only if you know how to do it. Write the code using C++ (not Python or Java). Show and explain everything neatly. COMMENTS (7.5% of programming assignment grade): Your program should have at least ten (10) different detailed comments explaining the different parts of your program. Each individual comment should be, at a minimum, a sentence explaining a particular part of your code. You should make each comment as detailed as necessary to fully explain your code. You...

  • Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If...

    Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If you do actually win the lottery, please be sure to give back to your alma mater, Orange Coast College. We will be happy to put your name on the building!**) Ok, time to get real. The Fantasy 5 (TM) lottery is a game in which 5 numbers from 1 to 36 are randomly drawn by the State of California. If you correctly guess all...

  • java/javafx assignment: Island Paradise just started running their city lotto. You've been tasked with writing a...

    java/javafx assignment: Island Paradise just started running their city lotto. You've been tasked with writing a program for them. The program is going to allow to user to first select their lotto numbers. The program will then randomly generate the winning lotto numbers for the week and then check the winning numbers against the random ticket the user played in the Lotto to see how many numbers the user guessed correctly. The rules for lotto work as follows: Select 7...

  • Please use python and show the code you used. Question 2 5 pts from sympy import...

    Please use python and show the code you used. Question 2 5 pts from sympy import sieve sieve.extend_to_no(999) primes - set (sieve._list) The code above creates a set of prime numbers, stored in the variable primes. Check whether or not the following list of numbers is prime, by checking if it is in the set primes. Keep the sequence of True/False values in the order given, and express that sequence as a 14-digit binary number. Enter the equivalent decimal integer...

  • I am just curious about this question... please can you answer with applying indent and space...

    I am just curious about this question... please can you answer with applying indent and space clearly. Furthermore, can you make answer shortly as possible..? This is a python question Question 6.34 The two-player card game war is played with a standard deck of 52 cards. A shuffled deck is evenly split among the two players who keep their decks face-down. The game consists of battles until one of the players runs out of cards. In a battle, each player...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT