我正在制作一个货币转换器。如何让 python 同时接受整数和浮点数?
我就是这样做的:
def aud_brl(amount,From,to):
ER = 0.42108
if amount == int:
if From.strip() == 'aud' and to.strip() == 'brl':
ab = int(amount)/ER
print(ab)
elif From.strip() == 'brl' and to.strip() == 'aud':
ba = int(amount)*ER
print(ba)
if amount == float:
if From.strip() == 'aud' and to.strip() == 'brl':
ab = float(amount)/ER
print(ab)
elif From.strip() == 'brl' and to.strip() == 'aud':
ba = float(amount)*ER
print(ba)
def question():
amount = input("Amount: ")
From = input("From: ")
to = input("To: ")
if …Run Code Online (Sandbox Code Playgroud) 这是在 pygame. 当我按向左箭头键时,如何翻转图像(假设猪向右看的图像)向左看,并且即使我不按任何键或按向上和向下箭头键。那么,当我按向右箭头键时,如何再次将其切换回向右看,并使其保持这样,即使我不按任何键或按向上和向下箭头键。
我知道我必须使用pygame.transform.flip()。但是,我不知道如何将其放入我的代码中。
这是主要游戏:
import sys
import pygame
from pig import Pig
pygame.init()
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Flying Pig")
blue_sky = 135, 206, 250
brown = 139, 69, 19
pig = Pig(screen)
while True:
# Accept events
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# Keydown events
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
pig.moving_right = True
elif event.key == pygame.K_LEFT:
pig.moving_left = True
elif event.key == pygame.K_UP: …Run Code Online (Sandbox Code Playgroud)