日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python编写程序模拟硬币的投掷、假设0表示硬币的反面_修改了Python中的硬币投掷程序,无法完成循环...

發(fā)布時(shí)間:2025/3/15 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python编写程序模拟硬币的投掷、假设0表示硬币的反面_修改了Python中的硬币投掷程序,无法完成循环... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

謝謝你們的幫助!以下是完整的代碼:D'''

_MBE_

CIS-115-09

Lab 6-1

Write a python program, using modules / functions, to simulate flipping

a coin using a random number generator.

If the random number generator returns a 0 consider that a “tails”,

and a return of a 1 a “heads”.

At the beginning of the program ask the user how many times to flip the coin,

keep track of the total “heads” and “tails” and print the results after

the coin has been flipped the requested number of times.

Allow the user to enter another number of times to flip the coin

and re-run the program.

An input of zero (0) times to flip the coin will terminate the program.

'''

print; printHeader = raw_input("Please enter your name: ")

print; print printHeader, "| Lab 6-1"; print

raw_input("Press [ENTER] to continue...."); print

import random # importing the random library to allow for use of random

#random functions later on

# declaring the variable to take input on how many times to flip the coin

timesToFlip = int(input("Enter the number of times to flip the coin: ")); print

# defining the function for the coin flip game

def coinFlipGame(timesToFlip):

coinHeads = 0 # used to store how many times the coin is heads

coinTails = 0 # used to store how many times the coin is tails

accumulator = 0 # ensures that the coin is only flipped a certain number of times

while accumulator < timesToFlip:

coinFlip = random.randint(0,1)

if coinFlip == 1:

accumulator += 1

coinHeads += 1

print "After", accumulator, "flip(s) of the coin, the result was heads!"

raw_input("Press [ENTER] to continue...."); print

else:

accumulator += 1

coinTails += 1

print "After", accumulator, "flip(s) of the coin, the result was tails!"

raw_input("Press [ENTER] to continue...."); print

print "Flips:", accumulator, "| Heads:", coinHeads, "| Tails:", coinTails

while timesToFlip: # a loop to allow the program to keep running until

#an appropriate kill code is entered

coinFlipGame(timesToFlip)

timesToFlip = input("Enter the number of times to flip the coin: "); print

if timesToFlip == 0:

print "You have ended the game. Goodbye!"; print

raw_input("Press [ENTER] to end program....")

# end program

總結(jié)

以上是生活随笔為你收集整理的python编写程序模拟硬币的投掷、假设0表示硬币的反面_修改了Python中的硬币投掷程序,无法完成循环...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。