Question

In: Computer Science

In Python... Write a program that randomly assign participants for a study (use the random module)....

In Python...

Write a program that randomly assign participants for a study (use the random module).

The program should:

  • Display a message stating its goal
  • Prompt the user to enter
    • Number of participants in the study (sample size)
    • Minimum age of the participants
    • Maximum age of the participants
  • Based on these specifications, randomly assign for each participant:
    • Gender (you can use "1" for Male and "2" for Female)
    • Age
  • The program should calculate and display:
    • Total number of male participants and their average age
    • Total number of female participants and their average age

Remember:

  • Do not use too advanced functions that is not needed.
  • Make sure to include comments that explain all your steps (starts with #).

Solutions

Expert Solution

# Code
import random
print("Program that randomly assign participants for a study (use the random module).")
n = int(input("Enter number of participants in the study: "))
minAge = int(input("Enter minimum age of the participants: "))
maxAge = int(input("Enter maximum age of the participants: "))
gender = []
age = []
for i in range(n):
    gender.append(random.randint(1,2))
    age.append(random.randint(minAge,maxAge))
maleCount = 0
femaleCount = 0
sumMaleAge = 0
sumFemaleAge = 0
for i in range(n):
    if(gender[i]==1):
        maleCount += 1
        sumMaleAge += age[i]
    else:
        femaleCount += 1
        sumFemaleAge += age[i]
print("Total number of male participants =",maleCount)
print("Male participants average age =",(sumMaleAge/maleCount))
print("Total number of female participants =",femaleCount)
print("Female participants average age =",(sumFemaleAge/femaleCount))


Related Solutions

use Python datetime module, strftime Write a program that processes the following textfile and prints the...
use Python datetime module, strftime Write a program that processes the following textfile and prints the report shown below. Textfile: Ask the user for the filename and BE SURE TO CHECK THAT IT EXISTS. The file will contain lines which each contain 2 strings (bookTitle and publicationDate) separated by a comma and a space. Note that the title of the book might contain spaces! Example of the textfile: Gone Girl, 5-24-2012 To Kill A Mockingbird, 7-11-1960 Harry Potter and the...
Use PYTHON --Nested Lists and DateTime Module. Write a program that does the following: Reads information...
Use PYTHON --Nested Lists and DateTime Module. Write a program that does the following: Reads information from a text file into a list of sublists. Be sure to ask the user to enter the file name and end the program if the file doesn’t exist. Text file format will be as shown, where each item is separated by a comma and a space: ID, firstName, lastName, birthDate, hireDate, salary Store the information into a list of sublists called empRoster. EmpRoster...
Write a Python program (with comments) to do the following: Assign the value '2+1' to a...
Write a Python program (with comments) to do the following: Assign the value '2+1' to a variable str1. Use the eval() function to evaluate str1and assign the result to a variable num1. Ask the user to input their birth month and assign it to a variable month and then print it with a suitable message. Determine the number of letters in month and display the result with a suitable message. Determine how many times the letter 'r ' occurs in...
Random Number Guessing Game (python) *use comments Write a program guess.py that generates a random number...
Random Number Guessing Game (python) *use comments Write a program guess.py that generates a random number in the range of 1 through 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." If the user guesses the number, the application should congratulate the...
IN PYTHON: Write a program to study countries and their capitals. The program will store country:capital...
IN PYTHON: Write a program to study countries and their capitals. The program will store country:capital information and allow the user to quiz themselves. These two functions are required for this assignment. You may add other functions that you deem appropriate: - menu()   This function, which displays all the user options to the screen, prompts the user for their choice and returns their choice. This function will verify user input and ALWAYS return a valid choice. - addCapital(dict) This function...
1. Write a python program to create a list of integers using random function. Use map...
1. Write a python program to create a list of integers using random function. Use map function to process the list on the expression: 3x2+4x+5 and store the mapped elements in another list. Now use filter to do sum of all the elements in another list. 2. Write a function that takes n as input and creates a list of n lists such that ith list contains first 10 multiples of i. 3. Write a function that takes a number...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
We wonder if caffeine facilitates the learning of nonsense syllables. We randomly assign participants to one...
We wonder if caffeine facilitates the learning of nonsense syllables. We randomly assign participants to one of two groups. People in the experimental group drink 2 cups of coffee and then learn a list of nonsense syllables. People in the control group drink 2 cups of plain water and then learn the same list. We record the number of trials required to perfectly learn the list for each participant. Did participants who drank the coffee learn the list faster than...
We wonder if caffeine facilitates the learning of nonsense syllables. We randomly assign participants to one...
We wonder if caffeine facilitates the learning of nonsense syllables. We randomly assign participants to one of two groups. People in the experimental group drink 2 cups of coffee and then learn a list of nonsense syllables. People in the control group drink 2 cups of plain water and then learn the same list. We record the number of trials required to perfectly learn the list for each participant. Did participants who drank the coffee learn the list faster than...
Challenges Using Python 3. Write a program that displays the name of a card randomly chosen...
Challenges Using Python 3. Write a program that displays the name of a card randomly chosen from a complete deck of 52 playing cards. Each card consists of a rank (Ace. 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King) and a suit (Clubs, Diamonds, Hearts. Spades).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT