摘要: import random class Coin: def __init__(self, rare=False, clean=True, **kwargs): for key,value in kwargs.items(): setattr(self,key,value) self.is_rare = rare ... 阅读全文
posted @ 2017-07-18 22:41 mxyzptlk 阅读(118) 评论(0) 推荐(0)
摘要: board = [' ' for i in range(9)] def print_board(): row_1 = '|{}|{}|{}|'.format(board[0], board[1], board[2]) row_2 = '|{}|{}|{}|'.format(board[3], board[4], board[5]) row_3 = '|{}|{}|... 阅读全文
posted @ 2017-07-17 17:33 mxyzptlk 阅读(270) 评论(0) 推荐(0)
摘要: def weight_converter(gram): total_weight = gram / 1000 return str(total_weight) + 'KG' the_weight = weight_converter(3000) print(the_weight) 阅读全文
posted @ 2017-07-16 22:34 mxyzptlk 阅读(192) 评论(0) 推荐(0)
摘要: # get sentence from user original = input('Please enter the sentence you want to translate: ').strip().lower() # split sentence to words words = original.split() # loop through words and translate to... 阅读全文
posted @ 2017-07-16 21:17 mxyzptlk 阅读(253) 评论(0) 推荐(0)
摘要: # 1 vowels = 0 consonants = 0 for letter in 'supercalifragilisticexpialidocious': if letter.lower() in 'aeiou': vowels = vowels + 1 elif letter == ' ': pass else: ... 阅读全文
posted @ 2017-07-16 17:01 mxyzptlk 阅读(110) 评论(0) 推荐(0)
摘要: from random import choice questions = ['Why is the sky blue? ', 'Why do cats have 4 legs? ', 'Why is the summer hot? '] question = choice(questions) answer = input(questi... 阅读全文
posted @ 2017-07-16 16:41 mxyzptlk 阅读(142) 评论(0) 推荐(0)
摘要: films = { 'Finding Dory': [3, 5], 'Bourne': [18, 7], 'Tarzen': [15, 9], 'Ghost Busters': [12, 5] } while True: choice = input('Please enter the selected film: ').title().strip() ... 阅读全文
posted @ 2017-07-15 16:53 mxyzptlk 阅读(199) 评论(0) 推荐(0)
摘要: # create a dictionary students = {"Alice": 24, "Bob": 26, "Clark": 23, "Dan": 28, "Emma": 31} # add entry to a dictionary students['Fred'] = 27 # alter an entry students['Alice'] = 25 # delete entry ... 阅读全文
posted @ 2017-07-14 22:34 mxyzptlk 阅读(161) 评论(0) 推荐(0)
摘要: known_user = ['Alice', 'Betty', 'Charlie', 'Daniel', 'Edison'] while True: print('Hi, I am a ridiculous user system') name = input('Please enter your name: ').strip().capitalize() if nam... 阅读全文
posted @ 2017-07-14 00:11 mxyzptlk 阅读(134) 评论(0) 推荐(0)
摘要: python_list = ['ace', 'list ', ['in ', 9, 'another list'], 3, 6, True, False] # output = python_list[1] + python_list[2][0] + python_list[2][2] # print(output) print(python_list[1] + python_list[2][0... 阅读全文
posted @ 2017-07-13 21:43 mxyzptlk 阅读(90) 评论(0) 推荐(0)