1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
natita [175]
2 years ago
7

What's wrong with my program? Here is my code , if the user wants a 3rd card dealt they, have to select yes and the total will b

e for 3 cards. If they don't, then the total is for 2 cards.? I also need to print the total for both the dealer and the user and determine the winner of the game?
# import random
import random
def main():
# greet the user
print("Hello! Welcome to my card game!")
# deal the user a random card between 1 and 10
num1 = random.randint(1,10)
print("You drew a", num1)
# deal the user another random card (between 1 and two)
num2 = random.randint(1,10)
print("You drew a", num2)
num3 = random.randint(1,10)

# deal the user a third card?
again = input("Would you like to draw a 3rd card? Y or N? ")
d_total = random.randint(10,21)
u_total = (num1) + (num2) + (num3)
u_total1 = (num1) + (num2)
if again == "Y" or "y":

print("You drew a", num3)


if (u_total > d_total) and (u_total < 21):
# the user wins
print("Congratulations! You won!")
print("You drew a",num1,",", "a",num2,"," "and a",num3, "for a total of",u_total)
if again == "N" or "n":
print("You drew a", num1,"and a",num2, "for a total of",u_total1)


if (u_total > d_total) and (u_total < 21):


print("The dealer's total is", d_total)




else:

print("Sorry! You lose.")

main()
Computers and Technology
1 answer:
Mashcka [7]2 years ago
4 0

Your issue is on line 19 in your if statement. In python, if you have more than one condition in an if statement, you have to explicitly mention it after the or.

Your if statement is

if again == "Y" or "y":

However, this will always return true because the second statement simply asks "y".

To correct this, simply change the if statement to:

if again == "Y" or again == "y":

This will correct your code.

Another thing to consider is to always convert a userinput (whenever possible) to one version, this can be accomplished in your code by converting "again" into one version by using the .lower function.

again = input("Would you like to draw a 3rd card? Y or N? ")

again = again.lower()

Hope this helps!

You might be interested in
The term BIOS stands for
iren2701 [21]
Basic Input-Output System
8 0
3 years ago
Describe the three criteria you should use to determine if an online media source should be included in your paper or presentati
VikaD [51]
<span>To use an online resource, it should be relevant to the topic. It should be credible, coming from an expert on the topic. Finally, it should be valid, coming from a source that is based in truth or fact.</span>
7 0
3 years ago
Read 2 more answers
Does speedtest report megabytes per second or megabits
Lesechka [4]

that could be both *shrugging*

7 0
3 years ago
Which of these statements regarding​ time-cost tradeoffs in CPM networks is​ true?
g100num [7]

Answer:

B. Crashing  is not possible unless there are multiple critical tasks.

8 0
3 years ago
Which search strategy explores nodes from the initial state as well as the goal state?
Simora [160]
Pretty sure it’s c! I’m not 100% tho sorry if I’m wrong have a nice day:)
5 0
3 years ago
Read 2 more answers
Other questions:
  • If you're found to be at fault in _____, your driver license will be canceled within 90 days unless you complete a 12-hour Advan
    10·2 answers
  • Which of the following circuits has an equivalent resistance of 30 Ω?
    8·2 answers
  • This diagram shows who is responsible in preventing cyberbullying. A flowchart. Top box is labeled Cyberbullying can be prevente
    14·2 answers
  • List the seven basic internal components found in a computer tower
    6·2 answers
  • What type of data would a RDBMS store in a linked list, two-way linked list, or B-trees? What are the advantages and disadvantag
    5·1 answer
  • I still haven't figured out how to award someone branliest will someone help me? If you explain to me how to do it i will do awa
    14·1 answer
  • 100 POINTS PLEASE HELP Type the correct answer in the box. Spell all words correctly.
    15·1 answer
  • This assignment is based on Exercise 8.4 from your textbook. Each of the following Python functions is supposed to check whether
    11·1 answer
  • Select the correct answer.
    8·1 answer
  • One of the most notable impacts of IT on business is improved
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!