salma_51999
Badges: 7
Rep:
?
#1
Report Thread starter 1 year ago
#1
>>> roundWinner = "Player"
def PlayRound(winner):
playercard = playerhand.pop(0)
computercard = computerhand.pop(0)

SyntaxError: multiple statements found while compiling a single statement
>>>
whats wrong and what does that syntax mean?
0
reply
Spanx
Badges: 18
Rep:
?
#2
Report 1 year ago
#2
Have you indented your code and what is your function supposed to return? A def should return something when you run it...
0
reply
winterscoming
Badges: 19
Rep:
?
#3
Report 1 year ago
#3
Is this in a .py file or did you paste this into the IDLE command line? If you haven't already done so, try putting it into a .py file and running the script -- it may be that the command-line only allows you to run one instruction at a time.
0
reply
winterscoming
Badges: 19
Rep:
?
#4
Report 1 year ago
#4
(Original post by Spanx)
Have you indented your code and what is your function supposed to return? A def should return something when you run it...
Functions don't need to return anything - for example: https://repl.it/repls/AwkwardPuzzledBaitware
0
reply
Spanx
Badges: 18
Rep:
?
#5
Report 1 year ago
#5
(Original post by winterscoming)
Functions don't need to return anything - for example: https://repl.it/repls/AwkwardPuzzledBaitware
Idented to make sure your function is in it's own block and if you're not defining a function to return something what are you using it for?
0
reply
salma_51999
Badges: 7
Rep:
?
#6
Report Thread starter 1 year ago
#6
import random
def globalvars():
global dogfilename
global playerhand
global computerhand
dogsfilename = "dogs.txt"
playerhand = []
computerhand = []

def menu():
choice()
numberofcards(input)
answer = input()
print("Welcome to Celebrity Dogs")
print("Write A to start game or B to Quit")

answer=False

if answer == ("A"):
print("Let's Play")
answer=True
elif answer == ("B"):
print("Bye then")
else:
print("Invalid answer, Select A or B.")

def numberofcards():
number()
number=int(input("Enter an even number that is less than 30 and more than 4.")
if number < 30 and number > 4 and number % 2 == 0:
print("OK, here are the cards")
else:
print("Invalid")


def setcards(numberofcards): #sout out cards
dogfile=open(dogsfilename,"r")
cards=()
for line in range (0,numberofcards):
dogFromFile = dogsFile.readline()
dogName=dogFromFile.rstrip("\n")
exercise = random.randint(1,5)
intelligence = random.randit(1,100)
Friendliness = random.randit(1,10)
Drool = random.randit(1,10)
cards.add([dogname,exercise,intelligence,fr iendliness,drool])
dogsFile.close()
random.shuffle (cards)
return cards

def arrangecrads(deck): #dealing cards
while len (deck)>0:
# remove and store the top card from each player's deck
playerhand.append(deck.pop()) # pop the last card from the deck and add it to the player's deck
ComputerHand.append(deck.pop())
def playgame (numberofcards):
deck = setcards(numberofcards)
ArrangeCards(deck)
roundWinner = "Player"
def PlayRound(winner):
playercard = playerhand.pop(0)
computercard = computerhand.pop(0)

#Display the player's card
print("Your card is: ")
displaycard(playercard)
if winner == "player": # player wins
category = choosecategory() # player chooses an attribute/category
else: # computer wins
category=random.randit(1,4) # computer chooses random attribute because a computer can't choose for itself.
# use the category number too find the score of each deck
playerscore = playercard[category]
computerscore = computercard[category]
# set the list of categories/attributes
categories = ("Name", "Excersie", "Intelligence", "Drool")
categoryName = categories[category]
#Use the category number to find the category name from the global variables called categories.
print("The computer's card is: ") # display computer's card
displaycard(ComputerCard)
if winner == "Computer":
print("The computer has chosen", categoryname)
print("Player's",categoryname, " = ",playerscore)
print("Computer's",categoryname, " = ",Computerscore)

can someone check this xx
0
reply
winterscoming
Badges: 19
Rep:
?
#7
Report 1 year ago
#7
(Original post by Spanx)
Idented to make sure your function is in it's own block and if you're not defining a function to return something what are you using it for?
It could be all kinds of things - for example, to output something to the screen, or write something into a file/database or sending data to someone's API, or maybe even modifying an object/dictionary which is passed in one of its parameters. It's something you'd probably see quite a lot when a program is broken down in a way where 'write' and 'output' operations are neatly separated away from 'read'/'input' operations and away from any functions which perform any kind of calculations or core logic.
0
reply
winterscoming
Badges: 19
Rep:
?
#8
Report 1 year ago
#8
(Original post by salma_51999)
can someone check this xx
Unfortunately TSR loses all of the formatting when you paste code, so it's impossible to see what's happening. Try pasting it into this website instead:
http://repl.it/languages/python3
0
reply
salma_51999
Badges: 7
Rep:
?
#9
Report Thread starter 1 year ago
#9
(Original post by winterscoming)
It could be all kinds of things - for example....
ok, thanks xx

https://repl.it/repls/CrushingFamiliarFlatassembler
I copied it out on here and the syntax's are still there

def numberofcards():
number()
number=int(input("Enter an even number that is less than 30 and more than 4.")
if number < 30 and number > 4 and number % 2 == 0: #there ~ the colon is in red
print("OK, here are the cards")
else:
print("Invalid")
0
reply
entertainmyfaith
Badges: 21
Rep:
?
#10
Report 1 year ago
#10
moved this to computer science
0
reply
shivampaw
Badges: 11
Rep:
?
#11
Report 1 year ago
#11
Can you send the dogs.txt file as well pls
0
reply
winterscoming
Badges: 19
Rep:
?
#12
Report 1 year ago
#12
(Original post by salma_51999)
ok, thanks xx

https://repl.it/repls/CrushingFamiliarFlatassembler
I copied it out on here and the syntax's are still there

def numberofcards():
number()
number=int(input("Enter an even number that is less than 30 and more than 4.")
if number < 30 and number > 4 and number % 2 == 0: #there ~ the colon is in red
You have an error on the previous line -- you're missing a 'closing' parenthesis at the end of the line -- here:
number=int(input("Enter an even number that is less than 30 and more than 4."))

In other words, your int() isn't being closed properly, but the error is showing up on the following line.
0
reply
shivampaw
Badges: 11
Rep:
?
#13
Report 1 year ago
#13
(Original post by winterscoming)
You have an error on the previous line -- you're missing a 'closing' parenthesis at the end of the line -- here:
number=int(input("Enter an even number that is less than 30 and more than 4."))

In other words, your int() isn't being closed properly, but the error is showing up on the following line.
I saw this too but then if you look at the repl link it is closed properly there🤔
0
reply
salma_51999
Badges: 7
Rep:
?
#14
Report Thread starter 1 year ago
#14
Hey guys Now i've checked stuff nothing is outputting when I run.https://repl.it/repls/CrushingFamiliarFlatassembler
0
reply
winterscoming
Badges: 19
Rep:
?
#15
Report 1 year ago
#15
(Original post by salma_51999)
Hey guys Now i've checked stuff nothing is outputting when I run.https://repl.it/repls/CrushingFamiliarFlatassembler
The program creates all of those functions but there's nothing which starts out by actually calling any of them -- you need to start somewhere by calling whichever function or functions are intended to start your program (Possibly the 'menu()' function?)

But the code seems to have a lot of spelling mistakes and other small errors. Is this your real code? have you ever actually run any of this code before?

For example, there is a have a function called 'numberofcards' but on Line 11, the code creates an empty tuple object with the same name 'numberofcards' which hides the name of the function, meaning that you end up with an error on Line 22 instead:
Code:
def menu():
  numberofcards=() # This line isn't doing anything useful - it's just causing an error further down
When writing code I'd recommend that you only ever write a few lines at any one time before running that code and testing it properly to make sure it works the way you expect. The more code you write, the more likely you are to introduce errors or broken logic and have a much harder time making it work and getting it right.

As things are right now, you've got a lot of errors - If you fix all the errors then make sure you do things in small pieces, making sure you test it along the way to get little bits of it working; otherwise even if you get the code running without errors it may not do what you're expecting. If you end up writing too much code with too many problems then you can reach a point where it's easier just to start again with a blank program.

Writing a big chunk of code all at once without running it or testing it can be a really difficult and time-consuming way of doing things because it means having lots of different bits which could possibly go wrong, likely spending a lot more time trying to fix mistakes and understand what's happening.

Also, you seem to be relying a lot on "global" variables (Variables which are visible and modifiable everywhere in your program) - this will make things harder to understand as your program grows as well since the you can end up with "spaghetti" logic (i..e. hard to see how the variables in your program are changing, and hard to see see where the logic begins and and ends - like a bowl of spaghetti) . There are other ways of working with variables without making them global -- you can use function parameters instead. for example:
https://repl.it/repls/VirtuousFrontCompiler


On a related note, there's a really helpful PDF document here with a few guidelines for helping to find errors:
https://pythonforbiologists.com/29-c...s-on-one-page/
0
reply
salma_51999
Badges: 7
Rep:
?
#16
Report Thread starter 1 year ago
#16
I did write my code in small chunks but whenever I add another subroutine, there are syntaxes in the previous subroutine.
My teacher told me to add all those global variables - I don't know why though.
I took out numberofcards() in the menu part and added it at the end of the odd even subroutine. Now it works, but if I select B to quit it still asks me to select a number >4 and <30.
Thank you for checking it.

EDIT: It's fine. I added import sys and sys.exit to stop it.
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

University open days

  • University of Hertfordshire
    All Subjects Undergraduate
    Sat, 16 Nov '19
  • University of Roehampton
    General Open Day Undergraduate
    Sat, 16 Nov '19
  • Swansea University
    Undergraduate Open Day Undergraduate
    Sat, 16 Nov '19

Which party will you be voting for in the General Election?

Conservatives (48)
18.82%
Labour (105)
41.18%
Liberal Democrats (52)
20.39%
Green Party (15)
5.88%
Brexit Party (7)
2.75%
Independent Group for Change (Change UK) (0)
0%
SNP (4)
1.57%
Plaid Cymru (5)
1.96%
Democratic Unionist Party (DUP) (0)
0%
Sinn Fein (0)
0%
SDLP (0)
0%
Ulster Unionist (0)
0%
UKIP (2)
0.78%
Other (2)
0.78%
None (15)
5.88%

Watched Threads

View All