Python Basic Applet

Source: Internet
Author: User

========================================

Guess the size of the game

#!/usr/bin/python

#-*-Coding:utf-8-*-


Import Random

s = Int (Random.uniform (1,100))

#print (s)

m = 1

i = 0

While M! = S:

m = Int (input (' Enter the integer you guessed: '))

i + = 1

if M > s:

print (' You guess the numbers are big, don't lose heart, keep trying ')

If M < s:

Print (' You guessed the number is small, don't lose heart, continue to refuel ')

if M = = s:

If I <= 4:

Print (' Guess right so soon, too divine ')

elif i = = 5:

Print (' 5 times to guess right, really bad ')

else:

Print I, "time to guess the right, congratulations."

break;

===============================


===============================

Scissors Mini Games


#!/usr/bin/python

#-*-Coding:utf-8-*-

Import Random

While 1:

s = Int (Random.randint (1, 3))

if s = = 1:

IND = "Stone"

elif s = = 2:

IND = "Scissors"

elif s = = 3:

IND = "cloth"

m = raw_input (' Input stone, scissors, cloth, input ' end ' ends the game: ')

blist = [' Stone ', ' scissors ', ' cloth ']

if (m not in blist) and (M! = ' End '):

Print "Input error, please re-enter! "

Elif (m not in blist) and (M = = ' End '):

Print "\ nthe game quits ..."

Break

elif m = = Ind:

Print "Computer out:" + ind + ", Draw! "

elif (M = = ' stone ' and ind = = ' scissors ') or (M = = ' scissors ' and ind = = ' cloth ') or (M = = ' cloth ' and ind = = ' stone '):

Print "Computer out:" + ind + ", you won! "

elif (M = = ' stone ' and ind = = ' cloth ') or (M = = ' scissors ' and ind = = ' stone ') or (M = = ' cloth ' and ind = = ' scissors '):

Print "Computer out:" + ind + ", you lost! "


===============================


===============================

Shake Sieve Game


#!/usr/bin/env Python3

#-*-Coding:utf-8-*-

Import Random

Import Sys

Import time


result = []

While True:

Result.append (int (random.uniform (1,7)))

Result.append (int (random.uniform (1,7)))

Result.append (int (random.uniform (1,7)))

Print result

Count = 0

index = 2

Pointstr = ""

While index >= 0:

Currpoint = Result[index]

Count + = Currpoint

Index-= 1

Pointstr + = ""

Pointstr + = str (currpoint)

If Count <= 11:

Sys.stdout.write (pointstr + "+" + "small" + "\ n")

Time.sleep (1) # Sleep one second

Break

Else

Sys.stdout.write (pointstr + "+" + "big" + "\ n")

Time.sleep (1) # Sleep one second

Break

result = []


===============================


===============================

99 Multiplication Table


#!/usr/bin/python

#-*-Coding:utf-8-*-

#九九乘法表


i = 1

While I:

j = 1

While J:

Print J, "*", I, "=", I * j, ",

if i = = J:

Break


J + = 1

If J >= 10:

Break

print "\ n"

i + = 1

If I >= 10:

Break

===============================


===============================

To remove whitespace from a string:


def trim (s):

While s[:1] = = ":

s = s[1:]

While s[-1:] = = ":

s = s[:-1]

return s


str = ' Runoob '

Print (Trim (str))

===============================


===============================

Decimal Turn binary


#!/usr/bin/python

#-*-Coding:utf-8-*-


Denum = Input ("Enter decimal number:")

Print Denum, "(10)",

Binnum = []

# binary binary number

While Denum > 0:

Binnum.append (str (denum% 2)) # Stack Press in

Denum//= 2

print ' = ',

While Len (binnum) >0:

Import Sys

Sys.stdout.write (Binnum.pop ()) # no Space output print ' (2) '

==============================


==============================

Judging prime numbers


#!/usr/bin/python

#-*-Coding:utf-8-*-

For NUM in range (2,100): # iterations 10 to 20 digits

For I in Range (2,num): # based on factor iterations

If num%i = = 0: # Determine the first factor

J=num/i # Calculates a second factor

# print '%d equals%d *%d '% (num,i,j)

Break # jumps out of the current loop

Else: # The else part of the loop

Print num, ' is a prime number '

==============================

=============================

# Print Hollow equilateral triangle

#!/usr/bin/python

#-*-Coding:utf-8-*-

rows = Int (raw_input (' input line number: '))

For I in range (0, rows):

for k in range (0, 2 * rows-1):

if (i! = Rows-1) and (k = = rows-i-1 or k = = rows + i-1):

Print "*",

elif i = = rows-1:

If k% 2 = = 0:

Print "*",

Else

Print "",

Else

Print "",

print "\ n"

==============================


Bubble sort

#!/usr/bin/python

#-*-Coding:utf-8-*-


Arays = [1,5,2,7,6,15,12,9]

For I in range (len (arays)):

For j in Range (i+1):

If arays[i] < Arays[j]:

# realize the interchange of a variable

ARAYS[I],ARAYS[J] = Arays[j],arays[i]

Print Arays

==========================


==========================

Print Diamond


#!/usr/bin/python

#-*-Coding:utf-8-*-


width = Int (5)

For row in range (width + 1):

For col in range (width + 1):

if (ABS (ROW-WIDTH/2) + ABS (COL-WIDTH/2)) = = WIDTH/2):

Print "*",

Else

Print "",

Print ""


====================================




Python Basic applet

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.