这是我的代码,正如我所说,我试图这样做,如果他们为section选项输入的内容不在任何一个frozensets中,它打印我所拥有的然后重新启动程序.
import sys
import os
temp = float(input('Please enter the temperature (In Celsius or Fahrenheit): '))
unit = str(input('Now, is this in Fahrenheit(F) or Celsius(C)? '))
Fahrenheit = frozenset(["F","f","Fahrenheit","fahrenheit","Fah","fah"])
Celsius = frozenset(["C","c","Celsius","celsius","Cel","cel"])
FahandCel = Fahrenheit & Celsius
if unit in Fahrenheit:
answerC = (temp-32)*5/9
print('\nYour original temperature of {}F is {}C'.format(temp,answerC))
if unit in Celsius:
answerF = temp*9/5+32
print('\nYour original temperature of {}C is {}F'.format(temp,answerF))
if unit not in FahandCel:
print('\nPlease actually enter something obvious next time.\nSuch as, F, C, …Run Code Online (Sandbox Code Playgroud) 我正在Python 3.4.1中制作一个Tic Tac Toe程序.我的代码如下:
def boardDraw():
board = 0,0,0,\
0,0,0,\
0,0,0
print(board[0] , "|" , board[1] , "|" , board[2], \
"\n----------\n" , \
board[3] , "|" , board[4] , "|" , board[5], \
"\n----------\n" , \
board[6] , "|" , board[7] , "|" , board[8])
boardDraw()
Run Code Online (Sandbox Code Playgroud)
输出:
0 | 0 | 0
----------
0 | 0 | 0
----------
0 | 0 | 0
Run Code Online (Sandbox Code Playgroud)
期望的输出:
0 | 0 | 0
----------
0 | 0 | 0
----------
0 | …Run Code Online (Sandbox Code Playgroud)