Questions about coin toss program output

Asked 2 years ago, Updated 2 years ago, 20 views

import random

countH=0
countT=0
print("H   T")
for n in range (0,100):
    num = random.randint(0, 1)
    if num ==0:
        print ("l")
        countH=countH+1
    else:
        print("    l")
        countT=countT+1
print(countH, "", countT)

It's a very simple coin toss program. I'd like to check on a few things.

In this state, the output result is

l
   l
   l
l

It looks like this.

I'm going to do this

1
     2
1

I'd like to change it like this and mark it like this way. I don't know how to do it without the help of a beginner.

probability python

2022-09-22 15:42

1 Answers

??

if num is 0:
    print("1")
    countH + = 1 // countH = countH + 1
else:
    print("    2")
    countT += 1

Am I not supposed to do this?


2022-09-22 15:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.