Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python I'm stuck trying to make A random number generator in Python.

D

Deleted member 613

Guest
Im trying to create a random number generator in Python but im stuck.
Could someone please help me.
I'm honestley so stuck. I'm better at C#
 
Last edited by a moderator:
It's actually quite easy to create a generator for a random number in Python.

If you want to generate just a single random number then:
Python:
import random as r # Imports Python's random module.                                                                    
                                                                                                                        
# Use r.randint(...) to generate a random number between 0 and 100, and then print it out.                              
print(r.randint(0, 100))

If you'd like to generate more than one random number, then use:
Python:
import random as r # Imports Python's random module.                                                                    
                                                                                                                        
# Generate 5 random numbers using r.randint(...) inside of a for-loop.                                                  
for I in range(5):                                                                                                      
     print(r.randint(0, 100))

I'd suggest giving a read at the documentation(Especially before asking a question, as your answer may be there): https://docs.python.org/3/library/random.html
 
It's actually quite easy to create a generator for a random number in Python.

If you want to generate just a single random number then:
Python:
import random as r # Imports Python's random module.                                                                  
                                                                                                                      
# Use r.randint(...) to generate a random number between 0 and 100, and then print it out.                            
print(r.randint(0, 100))

If you'd like to generate more than one random number, then use:
Python:
import random as r # Imports Python's random module.                                                                  
                                                                                                                      
# Generate 5 random numbers using r.randint(...) inside of a for-loop.                                                
for I in range(5):                                                                                                    
     print(r.randint(0, 100))

I'd suggest giving a read at the documentation(Especially before asking a question, as your answer may be there): https://docs.python.org/3/library/random.html
Ok thanks.I'm more of a C# person but i am looking towards Python later this year. Thx
Edit:Looks way easier than C#
 
You're welcome.

Python is an easy language to learn, mainly because it was designed with beginners in mind. But even then, somebody like yourself with prior experience in another programming-language, should be able to pick it up fast(If you don't know any fundamentals of object-oriented programming such as classes, you may find it hard depending on how you interpret and understand these concepts).

Good luck.
 
You're welcome.

Python is an easy language to learn, mainly because it was designed with beginners in mind. But even then, somebody like yourself with prior experience in another programming-language, should be able to pick it up fast(If you don't know any fundamentals of object-oriented programming such as classes, you may find it hard depending on how you interpret and understand these concepts).

Good luck.
Thanks.I'm planning to do my iGCSE for coding early, and Python is my preference, which is why i'm trying to get as much help as i can.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom