Question

Python help: Create two lists of 5 elements. The first list should be a series of...

Python help: Create two lists of 5 elements. The first list should be a series of questions whose answer is either "T" or "F" (true or false). The second list should be the correct answers to those questions ("T" or "F"). Write a program that asks the user each question in the question list and compares their answer to the answer in the answer list. Print out whether or not they got the question correct and print out their final score.

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

Note:

The code is written in python 2.

Code screenshot:

Code:

# These are the original answers

original_answers = ["T","F","F","T","T"]

# This list is used store the answers given by the user

user_answers = []

# This list contains questions which the user needs to answer

questions = ["Is 2 + 2 equals 5?","The larger a chili pepper is the hotter it is?","Is the 'black box' in an aeroplane black in color?","Does a adult human have 206 bones?","Is bone 5 times stronger than steel?"]

# Prompting the user how answers need to be answered

print("Enter T if you think the answer is true, else F")

# Iterating over questions

for question in questions:

    # Printing the question and reading user input

    user_answer = raw_input(question)

    # Appending the user answer to user_answers list

    user_answers.append(user_answer)

# Calculating the user score

final_score = sum(user_answer == original_answer for user_answer,original_answer in zip(original_answers,user_answers))

# Printing the user score

print("You scored {} out of {}".format(final_score,len(original_answers)))

Sample Output:

Add a comment
Answer #2

Python Code:


original_answers = ['T','F','T','F', 'F']
users_answers = []
questions=["Que 1","Que 2","Que 3","Que 4","Que 5",]

for i in range(5):
    print("Question No. "+str(i)+" is: " + questions[i])
    ans = input("Please input your answer(T/F): ").strip().upper()
    if ans!= 'T' and ans!= 'F':
        print("Please enter T/F only. No other answers are accepted")
        i=i-1
    else:
        users_answers.append(ans)
    print()
    print()

score = 0

for i in range(5):
    correct_ans = original_answers[i]
    user_ans = users_answers[i]
    if correct_ans == user_ans:
        score = score+1

print("Your score is "+ str(score) + " out of 5")

Add a comment
Answer #3

Python Code:


original_answers = ['T','F','T','F', 'F']
users_answers = []
questions=["Que 1","Que 2","Que 3","Que 4","Que 5",]

for i in range(5):
    print("Question No. "+str(i)+" is: " + questions[i])
    ans = input("Please input your answer(T/F): ").strip().upper()
    if ans!= 'T' and ans!= 'F':
        print("Please enter T/F only. No other answers are accepted")
        i=i-1
    else:
        users_answers.append(ans)
    print()
    print()

score = 0

for i in range(5):
    correct_ans = original_answers[i]
    user_ans = users_answers[i]
    if correct_ans == user_ans:
        score = score+1

print("Your score is "+ str(score) + " out of 5")

Add a comment
Answer #4

Python Code:


original_answers = ['T','F','T','F', 'F']
users_answers = []
questions=["Que 1","Que 2","Que 3","Que 4","Que 5",]

for i in range(5):
    print("Question No. "+str(i)+" is: " + questions[i])
    ans = input("Please input your answer(T/F): ").strip().upper()
    if ans!= 'T' and ans!= 'F':
        print("Please enter T/F only. No other answers are accepted")
        i=i-1
    else:
        users_answers.append(ans)
    print()
    print()

score = 0

for i in range(5):
    correct_ans = original_answers[i]
    user_ans = users_answers[i]
    if correct_ans == user_ans:
        score = score+1

print("Your score is "+ str(score) + " out of 5")

Add a comment
Know the answer?
Add Answer to:
Python help: Create two lists of 5 elements. The first list should be a series of...
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
  • In python: ScoreFinder is a function that takes in two lists and a string. The first...

    In python: ScoreFinder is a function that takes in two lists and a string. The first list is a list of strings (player names), the second list is a list of floats (player scores), and the string is a name (player to find). If the player to find exists in the list of player names, then print the name of that player along with their associated score (which is in the second list at the same index). If the player...

  • In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while...

    In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while loop or a for loop to print only odd numbers 1, 3, 5, 7, 9 *tip: you can use range () function, or a condition with ‘break’ (e.g, while count < 10) In python!: Create a program that print out 12 months of a year and associated numbers (e.g., January 1, February 2…). Two lists should be created, and then loop through the list...

  • Create a program that has 4 lists. One list has the title of 5 books. Another...

    Create a program that has 4 lists. One list has the title of 5 books. Another list has the price of the 5 books and another list has the quantity of the 5 books. Put all 3 lists into a Master List(the fourth list). Using a loop print out the Title of each book and the value of the inventory (quantity * price) # The book "100 Years of Solitude" has an inventory value of $568.78 # Use Python

  • use python 2a. Union (1 points) Make a union function which takes in 2 lists as...

    use python 2a. Union (1 points) Make a union function which takes in 2 lists as parameters and returns a list. It should return a list that contain all elements that are in either list. Your results list should contain no duplicates. For example, if the two lists are [1,5,6,5, 2] and [3,5, 1,9] then the result list is (1,5,6,2,3,9). Note that the list sizes don't have to be equal. Note that the input lists could have duplicates, but your...

  • NOTE: USE PYTHON CS160 Computer Science Lab 14 Working with lists, functions, and files Objective: Work...

    NOTE: USE PYTHON CS160 Computer Science Lab 14 Working with lists, functions, and files Objective: Work with lists Work with lists in functions Work with files Assignment: Part 1: Write a program to create a text file which contains a sequence of test scores. Ask for scores until the user enters an empty value. This will require you to have the scores until the user enters -1. After the scores have been entered, ask the user to enter a file...

  • Create a Python list (use first three letters of your name followed by the letter L...

    Create a Python list (use first three letters of your name followed by the letter L as the name of the list.) with the following data: 10, 20.0, 50.00, 7000, 7500, 7700, 7800, 8000, 9000, ‘python’. Display the entire list with an appropriate message. Display the 4th element in the list with an appropriate message. Display the first 3 values of the list only. Display all the values starting from the sixth element to the end of the list. Change...

  • 1)Given two lists L1 and L2, create a new list L3 consisting of the first element...

    1)Given two lists L1 and L2, create a new list L3 consisting of the first element of L1 and the last element of L2. For example, if L1=[1,2,3] and L2=["a","b","c"], L3 should be [1,"c"] 2)given a string s, create a new string odd_letters that contains only the odd letters of s (two ways to solve this problem are to use slicing, or a while or for loop), i.e. starting at the first letter or the zeroth index: if s="banana", odd_letters...

  • [Using Python] Create a program to generate one random question, from a list of 5, for...

    [Using Python] Create a program to generate one random question, from a list of 5, for each repeated run. Report the number of the correct answers after all five questions have been answered. Your 5 questions should be a simple math problem, like "what is 5-4?" use a while loop based on the number of questions use a counter variable to count the number of questions asked e.g. questionCount +=1 user a counter variable to keep track of the correct...

  • Python code: 1. This question practices the use of a list method. Assign to the variable...

    Python code: 1. This question practices the use of a list method. Assign to the variable grades a list of 10 letter grades from among ‘A’, ‘B’, ‘C’, ‘D’, and ‘F’. For example: grades = [‘A’, ‘F’, ‘C’, ‘F’, ‘A’, ‘B’, ‘A’, ‘C’, ‘A’, ‘B’] Write a Python expression that creates a list named frequency, in which the elements are the number of times each of the letters A, B, C, D and F appear in grades. For example, for...

  • Urgent must be done in C# create an instance of the “ testquestion” class in your main method. al...

    Urgent must be done in C# create an instance of the “ testquestion” class in your main method. allow the uswr to enter the teat question and its answer, it they want to. if they do not, then continue by creating a default queatuon and answer. please use the constructor methods here. Then, using the “tostring or _str_method, have it print out those variables as decribed above. call the “check answer” method and allow the user to continue attempting to...

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