Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm a beginner computer science student and using python in computer science 1. My assignment is to write a program that creates a spirograph. I think that the code is all right to do that, but when i run it, an error message pops up that says syntax error and it highlights down(), which is a common turtle command. I have no idea why. It said syntax error for main(), but then i restarted python and now it says there's an error in down(). Here's the code:
from turtle import *
from math import *
def xValue(R,r,p,t):
x=(R-r)*cos(t)-(r+p)*cos((R-r)/r*t)
def yValue(R,r,p,t):
y=(R-r)*sin(t)-(r+p)*sin((R-r)/r*t)
def initialPosistion():
t=2*pi
up()
goto(xValue(R,r,p,t),yValue(R,r,p,t)
down()
def iterating(R,r,p):
t = 2*pi
while t < 0:
t = t-0.01
goto(xValue(R,r,p,t),yValue(R,r,p,t)
up()
def main():
R = 100
r = 4
p = int(input("Enter p(10-100): "))
if p < 10 or p > 100:
input("Incorrect value for p!")
iterating(R,r,p)
input("Hit enter to close...")
main()
Missed a closing ) at the end of this line:
goto(xValue(R,r,p,t),yValue(R,r,p,t))
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
Hey so I’m writing a text-adventure game in python and made a typingprint function to make the text look like it was typed out. But when I try to use this function with inputs it will reply with None.
import random
import time
import console
import sound
import sys
def typingPrint(text):
for character in text:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.05)
console.set_color()
typingPrint('Hello! My name is Sawyer and I will be your guide
throughout this game. Heres a helpful hint, every time you enter
room you will have to battle a enemy.')
time.sleep(3)
player_name = input(typingPrint('\nBefore we begin why don\'t
you tell me your name: '))
How can I fix this?
This is because your function doesn't return anything so there is no text in the input prompt. To solve it, you will need to first call your function, then the input -
typingPrint('Hello! My name is Sawyer and I will be your guide throughout this game. Heres a helpful hint every time you enter a room you will have to battle a enemy.')
time.sleep(3)
typingPrint('\nBefore we begin why dont you tell me your name: ')
player_name = input()
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Question = input("Welcome to the meal chooser program. The base cost is $9.99. Would you like to choose beef, chicken, or the vegetarian option?:")
if Question.casefold() == "beef":
print("Thank you. Your total cost is","$",'{:.2f}'.format(B))
elif Question.casefold() == "chicken":
print("Thank you. Your total cost is","$", '{:.2f}'.format(C))
elif Question.casefold() == "vegetarian":
print("Thank you. Your total cost is","$", '{:.2f}'.format(V))
B = 9.99*1.02
C = 9.99*1.025
V = 9.99*1.03
Whenever I run this and input chicken, beef, or vegetarian it prompts me with a message that says that the values of B, C, and V are not defined, but they are.
Code runs (barring jumps like function calls and class initializations) linearly, top down. Because you initialize your variables at the bottom, your code has not created the values when you arrive at your if-else block. If you put your variables first, the code will run fine.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
i'm a beginner in python, i called a function "gravity" before defining it and when i tried running the code, the python interpreter seems to produce this error message
Traceback (most recent call last):
File "C:/Python34/day1.py", line 30, in <module>
if __name__ == "__main__": main()
File "C:/Python34/day1.py", line 22, in main
gravity(78,98)
UnboundLocalError: local variable 'gravity' referenced before assignment
Here is the code
def main():
person = people()
person2 = people("joel max")
print(person2.whatname())
gravity(78,98)
def gravity(mass,accel):
force = mass * accel
return force
if __name__ == "__main__": main()
i tried to adjust the indentation but it's still not working.
You tried to call gravity before you defined it. Also, there's no reason to define it within your main program; make it a separate, external function. After the below changes, your only problem is that there's no function people.
def gravity(mass,accel):
force = mass * accel
return force
def main():
person = people()
person2 = people("joel max")
print(person2.whatname())
gravity(78,98)
if __name__ == "__main__":
main()
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
Here is my code:
r = random.randint(1,10)
But for some reason it's giving me the error
NameError: name 'random' is not defined
Other info: Mac, Python, 3.4.0 pylauncher
You have to import the module random:
import random
r = random.randint(1,10)
# ...
>>> import random
>>> r = random.randint(1,10)
>>> r
10
you need to import the random library with the import keyword
import random
random.randint(1,10) #no. between 0 and 10
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am trying to make a mac address spoofer in python for my mac as i find other software to be unnecessary advance/hard to understand. First i want a choicebox asking what device you want to spoof but i can not get the if else statement to work. The point if if coice is the first then input this value elif the choice is the second one input that value. If none of the above, you did somthing wrong. and i am running python 2.7
TlDr; If Else Statement do not work as i want (python 2.7).
Here is the code:
#_._# Mac Changer #_._#
import easygui
msg = "What Device do you want to spoof you're mac addresse?"
title = "SpoofMyMac"
choices = ["en0 (Ethernet)", "en1 (WiFi)"]
choice = easygui.choicebox(msg, title, choices)
#####################################
if choice == choice[0]: #
easygui.msgbox("Ethernet") #
elif choice == choice[1]: # This is where the problem seems to be.
easygui.msgbox("Wifi") #
else: #
easygui.msgbox("chus somthin!") #
#####################################
Now this is just the begining of the code, anyone care to help me out with this if else statement?
In advance Thank you! :)
From what I can see, you just have a typo. You want to index choices, not choice:
if choice == choices[0]:
#index choices ^
easygui.msgbox("Ethernet")
elif choice == choices[1]:
#index choices ^
easygui.msgbox("Wifi")
else:
easygui.msgbox("chus somthin!")