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
Write an input command using the variable company_name.
Oxana [17]

Answer:

company_name = input("What if your company name?");

print("I hope " + company_name + "becomes successful!");

Explanation:

The input of the user becomes a variable which is then stored in order to print it out as a message.

4 0
3 years ago
5. Many vehicles have indicator lights telling you when your
I am Lyosha [343]

Answer:

A.

Explanation:

The rest is nearly impossible to detect or not worth the time.

8 0
3 years ago
Read 2 more answers
How do I add pictures to my questions on the mobile app?
taurus [48]
The camera is at the bottom of the screen,Take a pic
8 0
4 years ago
Explains why it is important to select the correct data when creating a chart
Liula [17]

Answer:

to be organized

Explanation:

<h2>because when you are organized to select the correct data, you won't confused </h2>
4 0
3 years ago
Carmina wants to move a paragraph to the right margin of the document she is working in. She moves her cursor to
MissTica

Answer:

Carmina should use Indent option in order to move a paragraph to the right margin of the margin she is working in.

Explanation:

Indents are used basically to display the blank spaces or distance of the paragraph from the left of right margin.

A simple indent moves the paragraph on either left margin side or right margin side as selected. In order to customize the indents:

  • Click on Home tab.
  • Locate Paragraph group.
  • Click on Indents and Spacing.
  • Now under the Indentation option, from the drop down menu name Special, we can choose an indent to be:

                         1. First Line

                         2. Hanging

  • Moreover, length of the indent can be adjusted.

<h3>I hope it will help you!</h3>
4 0
4 years ago
Read 2 more answers
Other questions:
  • A(n) ______ database stores data in tables that consist of rows and columns.
    5·2 answers
  • What number is needed to complete the pattern 66, 73, 13, 21, 52,_, 10, 20?
    12·1 answer
  • Which of these statements best describes an application programming interface?
    5·1 answer
  • Question 2 (2 points)
    9·1 answer
  • The use of IDPS sensors and analysis systems can be quite complex. One very common approach is to use an open source software pr
    9·2 answers
  • Does anyone know any nitro type hack??
    13·2 answers
  • What is the platform-neutral programming language that can run on Windows, Macintosh, or UNIX?
    15·1 answer
  • Create a project named ClassicBookSelector that contains a Form with a ListBox that lists at least five classic books that you t
    10·1 answer
  • Why is page formatting important??​
    10·2 answers
  • The recipient list cannot be edited.<br> Group of answer choices<br><br> True<br><br> False
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!