Question

Part I - Functions Write a program to do the following: • . Create two separate lists: [Female, M, 1, 4, Mail, 0, F]

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

Code:

#creating the function
def cleanGender(genderList):
for i in range(len(genderList)):
#decision statements to evaluate the items
if (genderList[i]=="Female" or genderList[i]=="F" or genderList[i]==1):
#setting the items
genderList[i]="Female"
elif (genderList[i]=="Male" or genderList[i]=="M" or genderList[i]==0):
genderList[i]="Male"
else:
genderList[i]="Undefined"
return genderList


#creating the function
def cleanNums(numlist):
for i in range(len(numlist)):
#decision statements to evaluate the items
if(0<=numlist[i]<=20):
#setting the items
numlist[i]="Low"
elif(20<numlist[i]<=40):
numlist[i]="Medium"
elif(40<numlist[i]<=60):
numlist[i]="High"
else:
numlist[i]="Out of range"
return numlist

list1=["Female","M",1,4,"Mail",0,"F"]
#using the function to print the list
print(cleanGender(list1))

list2=[-23,1,35,52,23,0,100]
#using the function to print the list
print(cleanNums(list2))

Output:

[Female, Male, Female, Undefined, Undefined, Male, Female] [Out of range, low, Medium, High, Medium,

Code Screenshot:

IDLE File Edit Format Run Options Window Help ques.py - /Users/ #creating the function def cleanGender(genderlist): for i in

Add a comment
Know the answer?
Add Answer to:
Part I - Functions Write a program to do the following: • . Create two separate...
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
  • C++ Write the following 7 routines as member functions in two separate classes -one involving a...

    C++ Write the following 7 routines as member functions in two separate classes -one involving a dynamic array and other a singularly linked list. -Also write inside the classes other appropriate functions like constructor/s, copy constructor, overloaded assignment operator, destructor, and other operator overloaded functions as needed. 1.To generate 100 random numbers between 1-100 in a randomData.txt file 2.To read the 100 random numbers from randomData.txt and store them in a data structure, 3.print the data in the data structure...

  • // use "for i in range(): //use len. //basic python //discrete mathematics Write a program in...

    // use "for i in range(): //use len. //basic python //discrete mathematics Write a program in Python (in a .py file) that: Makes two lists of 50 numbers each, where the first list is multiples of 5, and the second list is the first 50 squares: 1, 4, 9, 16, 25, 36, ....up to 2500. then I want you to make a third list by multiplying each individual pair in the two lists, so for example: 5 times 1 is...

  • Hello. I am using a Java program, which is console-baed. Here is my question. Thank you....

    Hello. I am using a Java program, which is console-baed. Here is my question. Thank you. 1-1 Write a Java program, using appropriate methods and parameter passing, that obtains from the user the following items: a person’s age, the person’s gender (male or female), the person’s email address, and the person’s annual salary. The program should continue obtaining these details for as many people as the user wishes. As the data is obtained from the user validate the age to...

  • This program should use a main function and two other functions named playlist and savelist as...

    This program should use a main function and two other functions named playlist and savelist as follows: The main function: The main function should create an empty list named nums and then use a loop to add ten integers to nums, each integer in the range from 10-90. NOTE: In Python, a list is a data type. See Chapter 7. The main function should then call the playlist function and savelist function, in that order. Both of these functions take...

  • Must be done in python and using linux mint Write a program to create a text...

    Must be done in python and using linux mint Write a program to create a text file which contains a sequence of test scores. Each score will be between 0 and 100 inclusive. There will be one value per line, with no additional text in the file. Stop adding information to the file when the user enters -1 The program will first ask for a file name and then the scores. Use a sentinel of -1 to indicate the user...

  • (a) Write a C program to print a list of all integers between 1 and 1,000...

    (a) Write a C program to print a list of all integers between 1 and 1,000 (inclusive) which are divisible by 7 but not by 13. The list should be printed to a file called "output.dat". Remember to close the file after use. (35%) (b) Explain what is meant by the C preprocessor. Explain the effect of the following line of code: #define SQUARE (x) (x) * (x) (25%) (c) Explain the concept of an array in C. Write down...

  • write a program for python 3 write the functions that could be used in an implementation...

    write a program for python 3 write the functions that could be used in an implementation of the game tic-tac-toe. Below are the definitions of the different functions. The code to test each function is currently in the main() of the lab10.py file. • A function to build the board. This method should create a list of the numbers 1 – 9 and return that list. build_board () -> list • A void function to display the board. (see the...

  • See notes in Lab4T1SHYPI.java Use the program Lab4T1SHYPL.java to answer the following questions. Part 1: Create...

    See notes in Lab4T1SHYPI.java Use the program Lab4T1SHYPL.java to answer the following questions. Part 1: Create a new program XYZ1234Lab4T1Part1.java and copy the body from Lab4T1SHYPIjava into the new program. In this new program, make the (29 points total a 1.a) Replace the sets of variables with arrays for each kind of data. Ex. shPubl, shPub2, shPub3, and shPub4 should be replaced with a single array StringIl shPub. Replace the variables for superHeros, shYear, shIssue, and shMovi Arrays should hold...

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

  • In this lab you will convert lab5.py to use object oriented programming techniques. The createList and...

    In this lab you will convert lab5.py to use object oriented programming techniques. The createList and checkList functions in lab5.py become methods of the MagicList class, and the main function of lab6.py calls methods of the MagicList class to let the user play the guessing game.                              A. (4pts) Use IDLE to create a lab6.py. Change the 2 comment lines at the top of lab6.py file: First line: your full name Second line: a short description of what the program...

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