This question already has answers here:
How to print without a newline or space
(26 answers)
Closed 5 years ago.
I have this code but i would like the numbers to be printed next to one another but it doesn't do that it just prints down the screen instead of filling up the screen.
import random
count=2
while count>0:
print(random.randint(0,1))
replace
print(random.randint(0,1))
with
print(random.randint(0,1), end="").
See https://docs.python.org/3/tutorial/inputoutput.html
Related
This question already has answers here:
How can strings be concatenated?
(7 answers)
String formatting in Python [duplicate]
(14 answers)
Closed 8 months ago.
import webbrowser
import random
idr = random.randint(10000, 9999999)
link = 'view&id='
webbrowser.open(link,idr)
with this code it generates the id and puts it at the end of the link as an id for an image however i have found that it wont work as it puts a space between the links = and the id
This question already has answers here:
How to get the size of a string in Python?
(6 answers)
Closed 1 year ago.
This is what have tried but it's not working
lens("Father")
it's len('Father') not lens('Father')
len(Father)
Your mistake is the 's' at the end of len's'
This question already has answers here:
Python list sort in descending order
(6 answers)
Closed 5 years ago.
This is my code:
#这是一个有关旅行的程序
place=['北京天安门','西安兵马俑','香港游乐园','日本秋叶原']
print(place)
print(sorted(place))
print(place)
place.sorted(reverse=true)
print(place)
When I run my code, something Wrong happens.
place.sorted(reverse=true)
or
sorted(place)
Using the 2nd way, how can I give (reverse=true)?
Just use sorted(place, reverse=True).
This question already has answers here:
Generate a random letter in Python
(23 answers)
Closed 5 years ago.
In python I want to know how to get random letter from string.
eg.
randomize("HELLO")
returns "L"
return (random.choice(string))
This question already has answers here:
Command prompt can't write letter by letter? [duplicate]
(3 answers)
Closed 6 years ago.
import random
import time
myStr="1234567890qwertyuiopasdfghjklzxcvbnm.,*/-+>£#$½{[]}\|!'^+%&/()=?_é><`;:"
def generator():
while True:
randomLetter=random.choice(myStr)
print(randomLetter,end="")
time.sleep(0.1)
generator()
I want to slow down my while loop . If i write time.sleep it doesnt output anything .If i delete end="" part it works but i still want to write everything in one line and I also tried with "sys.stdout.write" but it didnt work again.
do sys.stdout.flush() after print