Interactive Programming Forums
Login
Register
Home
Questions/Snippets/Exercises
Unanswered
Tags
Ask a Question
Post a Code Snippet
Post an Exercise
Welcome to Interactive Programming Forums, where you can ask questions, receive answers from other members of the community, post code snippets and post exercies.
All categories
Ruby
(3)
Python
(10)
PHP
(7)
Perl
(2)
SQL
(8)
Javascript
(6)
HTML
(20)
CSS
(4)
jQuery
(0)
XML
(3)
Code Snippets
(1)
Exercises
(4)
Other
(9)
I am have a problem with understanding a while loop, how to terminate it?
–2
votes
How do I terminate an event-controlled while loop? say I have to write a program that does factorials for integers?
The way I did it was like this:
n = int(raw_input())
a = 0
while n !=0
n = n-a
print n*n
n = int(raw_input())
I thought the last line was going to terminate the loop by constantly updating n for every loop. And how do I make this to be one correct answer?
posted
12 years
ago
in
Python
by
simphiwemakola12
(
1,010
points)
1 Answer
0
votes
n = int(raw_input())
a = 1
while n !=0
n = n-a
print n*n
a = a +1
answered
12 years
ago
by
Aguibou Ndiaye
(
240
points)
This doesn't terminate and does not give a correct answer of a factorial.
Related questions
+10
votes
1
answer
i have designed database using ms access , how can i convert it to php?
posted
13 years
ago
in
Other
by
Danny William
(
520
points)
+3
votes
1
answer
How to create a 5x4 (5 rows, 4 columns) table with one of rows having a column span set to 4 (colspan="4")?
posted
12 years
ago
in
HTML
by
yende
(
9,130
points)
0
votes
0
answers
How is this incorrect? It says invalid syntax
posted
9 years
ago
in
Python
by
ladayton69
(
7,080
points)
+10
votes
1
answer
in html 2,exercise 5 i have problem please F1
posted
12 years
ago
in
HTML
by
Milad1991
(
2,750
points)
html
+18
votes
1
answer
when your done with the course how do you create a website
posted
12 years
ago
in
PHP
by
Matthew Tembo
(
6,610
points)