利用for循環(huán)和while循環(huán)求n?
xStart=raw_input("please enter the int number:")
xInt= int(xStart)
count=0
while not xInt==count:
count +=1
print count #你輸入多少就從1顯示到這個(gè)數(shù)
還有就是求和:
xStart=raw_input("please enter the int number:")
xInt= int(xStart)
count= 0
sum= 0
while not xInt == count:
count += 1
sum += count
print sum
#這里顯示的sum是如果你要輸入數(shù)值5,則顯示sum=1+2+3+4+5的值.