小编rai*_*vbs的帖子

(Python)试图让"if not in"工作,它正在搜索一个冷冻集

这是我的代码,正如我所说,我试图这样做,如果他们为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 if-statement

4
推荐指数
1
解决办法
117
查看次数

(Python 3.x)如何在打印函数中的第一个变量之前添加空格?

我正在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)

python python-3.x

0
推荐指数
1
解决办法
101
查看次数

标签 统计

python ×2

if-statement ×1

python-3.x ×1