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

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

  • [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: Using Lists and Arrays! 5. In a program, write a function that accepts two arguments:...

    PYTHON: Using Lists and Arrays! 5. In a program, write a function that accepts two arguments: a list, and a number n. The program should generate 20 random numbers, in the range of 1 through 100, and assign each number to the list. The program should also ask the user to pick a number from 1 through a 100 and assign that number to n. The function should display all of the number in the list that are greater than...

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

  • Provide Python code that does the following: Create the following list in your program: lst1 =...

    Provide Python code that does the following: Create the following list in your program: lst1 = ["apple", "banana", "pear", "grapefruit", "pineapple", "grape", "guava", "plum", "peach"] Write code that then does the following: Print the last item in the list. Print the first item in the list. Print all but the last three items in the list. Print the first, third, fifth etc. items of the list. Print the second, fourth, sixth etc. items of the list. Parts A- E should...

  • 1) Which of the following is NOT true about a Python variable? a) A Python variable...

    1) Which of the following is NOT true about a Python variable? a) A Python variable must have a value b) A Python variable can be deleted c) The lifetime of a Python variable is the whole duration of a program execution.   d) A Python variable can have the value None.        2) Given the code segment:        What is the result of executing the code segment? a) Syntax error b) Runtime error c) No error      d) Logic error 3) What...

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