我正在做作业,答案正确回归,但我需要他们说5! = 120
而不是= 120
。我该怎么做呢?
def getInt():
getInt = int
done = False
while not done:
print("This program calcultes N!")
# get input for "N
N = int(input("Please enter a non-negative value for N: "))
if N < 0:
print("Non-Negative integers, please!")
else:
done = True
return N
def main():
n = getInt()
for i in range(n-1):
n = n * (i+1)
print("=" ,n)
main()
答案 0 :(得分:0)
# declare getInt()
def getInt():
getInt = int
done = False
while not done:
# write "this program calculates N!"
print("This program calcultes N!")
# get input for "N
N = int(input("Please enter a non-negative value for N: "))
# if N < 0 then
if N < 0:
print("Non-Negative integers, please!")
# else
else:
# done = true
done = True
# return N
return N
# main
def main():
n = entry = getInt()
for i in range(n-1):
n = n * (i+1)
print("{0}! = {1}".format(entry, n))
main()
结果:
/*
This program calcultes N!
Please enter a non-negative value for N: 5
5! = 120
*/
答案 1 :(得分:0)
我希望此代码有用。
print('Enter a positive integer')
a = int(input())
def factorial(n):
if n == 0:
return(1)
if n == 1:
return(1)
if n > 1:
return(n * factorial(n-1))
if a < 0:
print('Non-Negative integers, please!')
if a >= 0:
print(str(a) + '! = ' + str(factorial(a)))
答案 2 :(得分:0)
在- (float)tempo {
OSStatus err = noErr;
Float32 value = 1.0;
err = AudioUnitGetParameter(tempoUnit, kNewTimePitchParam_Rate, kAudioUnitScope_Global, 0, &value);
if (err != noErr) { // -10878
NSLog(@"Could not get tempo unit rate: %d", err);
}
return value;
}
中你可以使用另一个整数而不是n只是为了确保事情不会搞砸,你可以打印像joel所说for i in range(n-1)
而不是n整数你会使用