首页 > 代码库 > Hausaufgabe--Python 04

Hausaufgabe--Python 04

0---small games: number guess:

 

import random

answer = random.randint(1,10)

guess = int(input(‘please input your guess: ‘ ))

i = 2

while i :
  if guess != answer:
      if (guess > answer):
         print(‘oops, your guess is too much, you still have ‘+ str(i) + ‘ chances‘)
      else:
          print(‘your guess is too small, you still have ‘+ str(i) + ‘ chances‘)
      guess = int(input(‘try again: ‘ ))
      i = i-1
  else:
     print(‘correct! The answer is ‘+ str(answer)+ ‘! Did your mother know you are such a clever girl/boy !‘)
     break

 

1--- print a right-angled triangle

number = int(input(‘please input a integer: ‘))
k=number

while k:
    for i in range (k):
        print(‘ ‘,end=‘‘)
    for j in range(k):
        print(‘*‘, end=‘‘)
    print(‘‘)
    k=k-1

Hausaufgabe--Python 04