Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
hello my compiler must show 5 but says press any key to continue means nothing. can you solve my problem?
def result(num1,num2):
num3 = num1+num2
return num3
print(result(3,2))
The function call print(result(3,2)) is inside the function result after return (which also means it will never be reached). Simply move it out of the function
def result(num1,num2):
num3 = num1+num2
return num3
print(result(3,2)) # 1 Identation back
There is no such thing as compiler in python :)
Indentation is a part of syntax, your print became a part of function
You can try this
def result(num1,num2):
num3 = num1+num2
return num3
print(result(3,2))
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
So I've been trying to learn Python and after some easy codes (or whatever they are called) I am now trying to recreate a drinkinggame i always play with some friends. But for that i need this function to return a value which it doesn't do. Can anyone help me? (sorry for the bad English)
def throw():
dice = 6
List = []
i = 0
while i <= dice - len(List):
i +=1
List.append(random.randint(1,6))
return List
print(throw(List))
Your function isn't receiving any parameter, so don't pass anything.
import random
def throw():
dice = 6
List = []
i = 0
while i <= dice - len(List):
i +=1
List.append(random.randint(1,6))
return List
print(throw()) # here
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
This is all of the code in my while loop. I have declared the num outside the def statement jest so I don't get a global variable error.
Do you need to call all of the other def statements back to the loop?
num = 0;
def Loop(NumOfFeedback, num):
while num < NumOfFeedback:
classOne(Math,Science,English,History,Band,Choir,Spanish,French,German)
workloadOne(Little,Medium,aLot)
classTwo(MathA,ScienceA,EnglishA,HistoryA,BandA,ChoirA,SpanishA,FrenchA,GermanA)
workloadTwo(LittleA,MediumA,aLotA)
GPA(FourPO,ThreePFive,ThreePO,TwoPFive,TwoPO)
Age(A14,B15,C16,D17,E18)
num = num + 1
print num
You are only defining Loop but you are probably not running it.
When you def a function you just save it, but in order to run it you have to call it from your code.
add this at the end of your code (with the values you need):
Loop([NumOfFeedback], num)
You should change the name of the function to be lowercased (and other than just loop - super not clear).
Also move num = 0 down - right above the call.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to use step number in my Python script. This step number should be auto incrementing and I want to put it as part of logger. Is there any default option available for that?
The simplest way is to just wrap the logging call.
def step_log(message, *args, **kwargs):
logging.info("Step %d:" % step_log.counter + message, *args, **kwargs)
step_log.counter += 1
step_log.counter = 1
This could work in your case
`
step = 0
def sync_step():
global step
step = step+1
logging.info("message", sync_step())
logging.info("message", sync_step())
logging.info("message", sync_step())
print step # answer 3
`
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to caculate an church number by python below,but it prompt the errors when I use the input greater than 993,anyone whom had the experience told me what happend?
NUM0=lambda f: lambda x:x
SUCC=lambda n: lambda f: lambda x: f(n(f)(x))
def decoding(n):
num=NUM0
for i in xrange(n):
num = SUCC(num)
return num
def encoding(num):
f=lambda x:x+1
return str(num(f)(0))
print encoding(decoding(994)) # Why fails once greater than 993
You get a maximum recursion depth exceeded because python tries to protect itself against possible infinite recursive calls. Basically it stops itself in order not to cause a crash that could be a lot worse.
You can change the recursion limit with sys.setrecursionlimit (as said by #falsetru).
But as #ThomasWouters said in this answer:
Doing so is dangerous -- the standard limit is a little conservative, but Python stackframes can be quite big."
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))