values=[0]*10
values[0]=197
values[2]=-100
values[5]=350
values[3]=values[0]+values[5]
values[9]=values[5]/10
values[2]-=1
i=0
for index in values:
print("values[{0}] = {1}".format(i,index))
i=i+1
ratingCounters=[0]*11
for i in range(1,11):
ratingCounters[i]=0
print("Enter your Responses:")
for i in range (1,21):
response=5 #score=5 for all iterations
#response=input()
if(response<1 or response>10):
print("Bad response: {0}".format(response))
else:
ratingCounters[response]+=1
print("\n\n Rating | Number of Responses\n")
print(" ----- -------------------")
for i in range(1,11):
print(" {0} {1}".format(i,ratingCounters[i]))
Fibonacci=[0]*15
Fibonacci[0]=0
Fibonacci[1]=1
for i in range(2,15):
Fibonacci[i]=Fibonacci[i-2]+Fibonacci[i-1] #Calculation
for i in range(15):
print("{0}".format(Fibonacci[i])) #Print Result
primeIndex=2
primes=[0]*50
primes[0]=2
primes[1]=3
p=5
while(p<=50): #Outer Loop-1
isPrime=True
i=1
while(isPrime and p/primes[i]>=primes[i]): #Inner Loop
if(p%primes[i]==0):
isPrime=False
i+=1
if(isPrime==True):
primes[primeIndex]=p
primeIndex+=1
p=p+2
for i in range (primeIndex): #Outer Loop-2
print("{0}".format(primes[i]))
array_values=[0]*10
array_values[0:4]=[0,1,4,9,16]
for i in range(5,10):
array_values[i]=i*i
for i in range(10):
print("array values[{0}] = {1}".format(i,array_values[i]))
import sys #For sys.stdout.write()
word=['H','e','l','l','o','!']
for i in word:
sys.stdout.write("{0} ".format(i))
print("\n")
import sys #for sys.stdout.write()
baseDigits=['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']
convertedNumber=[0]*10
index=0
numberToConvert=234 #numberToConvert=input("Number to be converted?: ")
base=2 #base=input("Base?: ")
while True:
convertedNumber[index]=numberToConvert%base
index+=1
numberToConvert=numberToConvert/base
if(numberToConvert==0):
break
print("Converted Number= ")
index-=1
while(index>=0):
nextDigit=convertedNumber[index]
sys.stdout.write("{0} ".format(baseDigits[nextDigit]))
index-=1
print("\n")
import sys #For sys.exit()
numFibs=18 #numFibs=input("How many Fibonacci numbers do you want (between 1 and 75)? ")
if(numFibs<1 or numFibs>75):
print("bad number,sorry!")
sys.exit()
Fibonacci=[0]*numFibs
Fibonacci[0]=0
Fibonacci[1]=1
for i in range(2,numFibs):
Fibonacci[i]=Fibonacci[i-2]+Fibonacci[i-1]
for i in range(numFibs):
print("{0}".format(Fibonacci[i]))