Random Number Generator on Python
User input and the ability to manipulate that input are important elements with any programming language. It’s what separates a good program from a great program, one that allows the user to interact and see the results of that interaction.
If you’re feeling clever, see if you can pass the code through a Tkinter window or even the Ticker window that’s available on Number Guessing Game on Python.
Furthermore, the core of the code can be used in a text adventure game, where the character fights something and their health, along with the enemy’s, is reduced by a random number. This can be mixed with the previous code from Page 90’s Number Guessing Game, where we defined the stats for the adventure game’s character.
You can also introduce the Turtle module into the code and perhaps set some defined rules for drawing a shape, object or something based on a user inputted random value from a range of numbers. It takes a little working out but the effect is certainly really interesting.
For example, the code could be edited to this:
Whilst it’s a little rough around the edges, you can easily make it more suitable.
RNDNUMGEN.PY
It might be simple but this little piece of code will ask the user for two sets of numbers, a start and a finish. The code will then pluck out a random number between the two sets and display it.
from random import * print(“\n>>>>>>>>>>Random Number Generator<<<<<<<<<<\n”) nmb1=int(input(“Enter the start number: “)) nmb2=int(input(“Enter the last number: “)) x = randint(nmb1, nmb2) print(“\nThe random number between”,nmb1,”and”,nmb2,”is:\n”) print(x)
More Input
While an easy code to follow, it could be more interesting if you prompt the user for more input. Perhaps you can provide them with addition, subtraction, multiplication elements with their numbers.If you’re feeling clever, see if you can pass the code through a Tkinter window or even the Ticker window that’s available on Number Guessing Game on Python.
Furthermore, the core of the code can be used in a text adventure game, where the character fights something and their health, along with the enemy’s, is reduced by a random number. This can be mixed with the previous code from Page 90’s Number Guessing Game, where we defined the stats for the adventure game’s character.
You can also introduce the Turtle module into the code and perhaps set some defined rules for drawing a shape, object or something based on a user inputted random value from a range of numbers. It takes a little working out but the effect is certainly really interesting.
For example, the code could be edited to this:
from random import * import turtle print(“\n>>>>>>>>>>Random Turtle Image<<<<<<<<<<\n”) nmb1=int(input(“Enter the start number: “)) nmb2=int(input(“Enter the second number: “)) nmb3=int(input(“Enter the third number: “)) nmb4=int(input(“Enter the fourth number: “)) turtle.forward(nmb1) turtle.left(90) turtle.forward(nmb2) turtle.left(90) turtle.forward(nmb3) turtle.left(90) turtle.forward(nmb4) turtle.left(90)
Whilst it’s a little rough around the edges, you can easily make it more suitable.
Random Number Generator on Python |
0 Response to "Random Number Generator on Python"
Post a Comment