Post Reply 
 
Thread Rating:
  • 3 Votes - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding "while" loop
04-11-2016, 18:47
Post: #1
Coding "while" loop
0
Its me again needed of help creating loops in Pyhton language.

i must create a programm thats asks user a number. And the number he enters must generate random number 1 - 6.

Example: i enter 9 and result should be something like this.
2
6
1
4
2
3
2
4
3

generates 9 random number from 1 to 6 and each number must be in new line. in Pyhton new line is being marked with (\n)

This is as far ive managed to reach Big Grin Big Grin

Screenshot:

Find all posts by this user
Quote this message in a reply
04-11-2016, 21:32 (This post was last modified: 04-11-2016 21:35 by Predator01-cz.)
Post: #2
RE: Coding "while" loop
2
from random import randint
number = int(input("Enter a number: "))
i=0
while (i<number):
    random_number = randint(1,6)
    print('\n ',random_number)
    i=i+1

I've seen python for the first time in my life this semester, so please don't ask for anything more difficult

(edit: DoS threw my tabs out the window)
(edit2: DoS threw my spaces out the window too)

best I can do is Predat
Find all posts by this user
Quote this message in a reply
04-11-2016, 22:10
Post: #3
RE: Coding "while" loop
0
Thanks a lot Predator Smile

Find all posts by this user
Quote this message in a reply
04-12-2016, 08:17
Post: #4
RE: Coding "while" loop
1
Perhaps you should have used a
Code:
code
block, Predator. Wink

---------------------------------------------------------------------------------------------------------------
» I don't suffer from insanity. I enjoy every minute of it. «
---------------------------------------------------------------------------------------------------------------
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




» Powered by: betamaster.us «» Partner sites : vsee.us | knet.us |