I'm new to Python, i wanted to start learning it and here i try to rewrite a little code that i wrote in C# before. The program counts factorial, so if i type in 6 it would be 720. This is the python code:
import array
def countFactorial(tal):
summ = 1
for i in range(len(tal)):
summ *= i
i += 1
print("{} is".format(tal))
print("{}".format(summ))
return summ
def main():
lst = []
for i in range(5):
values = input("Type in a value: ")
lst.append(values)
for s in lst:
countFactorial(s)
# print(s)
main()
If the user would type in for example 6, this is what the program for now will type out: "6 is 0" (5 times).
This is a part of the for loop that i tried to rewrite from C# that doesn't work here. Obviously "tal" is passed on as a parameter here in the C# aswell.
for (int i = 1; i <= tal; i++)
{
summ *= i;
}
Console.WriteLine(tal + " is " + summ);
What i think i need is a while loop that needs to rund the summ code trough like for example 6 times. I've tried this but cannot work it out.
countFactorialyou modifyitwice, once infor i in range...and once ini += 1, the second modification is lost.talas the number (a string), so you are using the number of digits as the loop value.strobject, because you never convert the value to anintobject. String objects are sequences and have length, the number of characters in the string (solen('5') == 1).