Python realizes the popular game of Foreign casino craps (double dice) _python

Source: Internet
Author: User
Tags print print

How to run:

1. Open Python2 IDLE;
2. Input from craps import *
3. Enter the Run command as prompted. For example, enter play () when playing the game, and check the balance to enter Check_bankroll ();
Automatically play to see the winning on the input auto ()

craps.py

Import random point_set = False bet = Ten bankroll = 1000 Sim_win = 0 sim_lose = 0 print "" Welcome to the ' Seve
     N Star ' casino! You are are playing craps now, your started bankroll are ' $1000 ', the started bet is ' $ ', Command:pla Y (): "Rolling the Dices" Check_bankroll (): "Checking your current Balance" all_in (): Showing "hand" s Et_bet (): "Setting a new Bet" game (): "Check Your game Status" auto (): "It can be played automatically for Y ou until reach a specific bankroll "" "Def Roll (): D1 = Random.randrange (1,7) d2 = Random.randrange (1,7) print" Y ou rolled ", D1," + ", d2," = ", d1+d2 return D1 + d2 def play (): Global Point_set, Bankroll, point global sim_
    Win, Sim_lose if bankroll < Bet:print "Sorry, you can ' t play since you don ' t have enough to money!"
        Print "" "Do You wanna get more money?" 1:yes 2:no "" "Choice = Raw_input (" >> ") If choice = StR (1): Money = Raw_input ("How much does you wanna get?")  Bankroll + = Int (money) print "Your Current bankroll are:", bankroll if choice = = str (2): print "for playing!
  "Time! Next" Else:if not point_set:print print "New game. Your bet is: ', bet # for the ' the ' Roll R = Roll () if not point_set:if R in (7, one): ban Kroll + + bet Sim_win + 1 print "congratz! You won! Your bankroll are: ", bankroll Elif R in (2, 3,): Bankroll = bet Sim_lose + 1 print" Oop s! You lost! Your Bankroll is: ", bankroll Else:point = r Point_set = True print" Your point is "," [", p
      Oint, "]" # for subsequence rolls elif r = = 7:bankroll = Bet Sim_lose + = 1 Point_set = False Print "You crapped out!
  Your Bankroll is: ", bankroll elif r = = Point:bankroll + = Bet Sim_win + + 1 Point_set = False    Print "You made your point! Your Bankroll is: ", Bankroll def Set_bet (INP): Global bet, bankroll, point_set print if Point_se
    T:print "warning!"
    Print "The game has started, you'll lose half of your bet if resetting your bet!"
      prompt = Raw_input ("" "1:yes, I am wanna reset my bet!
              2:no, I don ' t wanna reset my bet! ' "' if prompt = = ' 1 ': Point_set = False Bankroll-= BET/2 print ' forfeiting current bet. Your Bankroll is: ", bankroll else:pass bet = Int (INP) print" New bet size is: ", Bet def all_in (): s
  Et_bet (Bankroll) def check_bankroll (): Global bet print "Your current balance is:", Bankroll Def game (): Total = Sim_win + sim_lose percent = float (sim_win)/total * print "So far, the games that you have been playing AR E: ", total print" Won ", Sim_win print" Lost ", sim_lose print" Overall, you have%d%% to win! "%percent def A Uto (): Game_status = True Purpose = raw_input ("How much are your gonna reach?") While Game_status:play () if bankroll = = Int (purpose) or bankroll = = 0:game_status = False Game ()

The above is the entire contents of this article, I hope to be able to learn Python help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.