Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help on first function
#7
(Apr-28-2021, 01:28 PM)snippsat Wrote: If run as script .py file and not in REPL then there is no >>>.
import random

def rand():
    for i in range(6):
        print(random.randint(1, 40))

rand()
Output:
22 35 8 12 21 29
if it's longer code with functions it can be better to run it as a script.
In REPL it would be like this.
>>> import random
>>> 
>>> def rand():
	for i in range(6):
		print(random.randint(1, 40))

		
>>> rand()
22
2
12
14
29
26
>>>


Perfect, many thanks!!
Reply


Messages In This Thread
help on first function - by jip31 - Apr-27-2021, 04:12 PM
RE: help on first function - by ndc85430 - Apr-27-2021, 04:47 PM
RE: help on first function - by jip31 - Apr-28-2021, 12:22 PM
RE: help on first function - by raarkil - Apr-28-2021, 12:55 PM
RE: help on first function - by jip31 - Apr-28-2021, 02:09 PM
RE: help on first function - by snippsat - Apr-28-2021, 01:28 PM
RE: help on first function - by jip31 - Apr-28-2021, 02:22 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020