Kritosein
June 12th, 2012, 04:39 PM
Hey guys, I'm 14 and I just started learning about programming so I am completely new at Python or any other programming languages, I am very motivated and I really want to learn so I started with this topic I found in this forum.
http://ubuntuforums.org/showpost.php?p=1984319
From there I found a link to some hetland.org link called instant hacking and atm I am trying to learn from there (I am only at half of the page)
but there is an exercise I should complete but I have no idea how to complete it. The exercise itself is that:
Write a program that continually reads in numbers from the user and adds them together until the sum reaches 100. Write another program that reads 100 numbers from the user and prints out the sum.
Problem with the first one is that I have no idea how to make the numbers add to itself in the loop. I basically have a working code but the problem is that I don`t know how to make it add to itself. And in the second the problem is the same. These are my codes I tried to use.
Note: I tried many codes and most of them aren't saved but 1 example on both problems:
First one:
num = input("Enter a number please: ")
numenough = 100
currentnum = num
while currentnum < numenough:
num = input("Enter another number please: ")
currentnum = currentnum + num
print "Yay, you exceeded 100"
Second one:
num = input("Enter a number: ")
allnum = num
for number in range (1,100):
num = input("enter a number: ")
allnum = allnum + num
print allnum
NOTE: Finally figured them both out while typing this topic :D
Typing stuff here really helps. Well anyways if you have any ideas how to make these types of codes easier then please tell me.
Oh, one more thing. I currently have a keyboard with russian layout and I have no idea how to make stars (you know like area of square is A times A. That "times" sign as well as less than and more than signs. These make writing almost any types of programs almost impossible. Is there a way I can change the keys? Thank you.
http://ubuntuforums.org/showpost.php?p=1984319
From there I found a link to some hetland.org link called instant hacking and atm I am trying to learn from there (I am only at half of the page)
but there is an exercise I should complete but I have no idea how to complete it. The exercise itself is that:
Write a program that continually reads in numbers from the user and adds them together until the sum reaches 100. Write another program that reads 100 numbers from the user and prints out the sum.
Problem with the first one is that I have no idea how to make the numbers add to itself in the loop. I basically have a working code but the problem is that I don`t know how to make it add to itself. And in the second the problem is the same. These are my codes I tried to use.
Note: I tried many codes and most of them aren't saved but 1 example on both problems:
First one:
num = input("Enter a number please: ")
numenough = 100
currentnum = num
while currentnum < numenough:
num = input("Enter another number please: ")
currentnum = currentnum + num
print "Yay, you exceeded 100"
Second one:
num = input("Enter a number: ")
allnum = num
for number in range (1,100):
num = input("enter a number: ")
allnum = allnum + num
print allnum
NOTE: Finally figured them both out while typing this topic :D
Typing stuff here really helps. Well anyways if you have any ideas how to make these types of codes easier then please tell me.
Oh, one more thing. I currently have a keyboard with russian layout and I have no idea how to make stars (you know like area of square is A times A. That "times" sign as well as less than and more than signs. These make writing almost any types of programs almost impossible. Is there a way I can change the keys? Thank you.