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...

  • 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....

  • 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...

  • You will write a two-class Java program that implements the Game of 21. This is a...

    You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...

  • 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...

  • 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; <...

  • 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...

  • Write a python program (recursive.py) that contains a main() function. The main() should test the following...

    Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...

  • PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end...

    PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end please include a main function that tests the functions that will go into a separate driver file. Prototypes int R_get_int (void); int R_pow void R Jarvis int start); void R_fill_array(int arrayll, int len); void R_prt_array (int arrayl, int len) void R-copy-back (int from[], int to [], int len); int R_count_num (int num, int arrayll, int len) (int base, int ex) 3. Build and run...

  • Python code question - you are given the grand prize(in USD) and the winning numbers. Your...

    Python code question - you are given the grand prize(in USD) and the winning numbers. Your program will read multiple tickets (6 selected numbers in each ticket) from the input file. For each ticket, the program calculates its prize won, and outputs the prize (in USD) to the output file. How to Play the Game? In each ticket, the player selects five numbers from a set of 69 white balls (numbered 1 to 69) and one number from 26 red...

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
ADVERTISEMENT