如何在python中进行简单的用户输入? [英] How do I do simple user input in python?

查看:80
本文介绍了如何在python中进行简单的用户输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在玩输入和变量.我正在尝试运行一个简单的功能:

I'm just playing with input and variables. I'm trying to run a simple function:

slope = (y2-y1)/(x2-x1)

我想提示用户输入y2y1x2x1.最简单,最干净的方法是什么?

I'd like to prompt the user to enter y2, y1, x2 and x1. What is the simplest, cleanest way to do this?

推荐答案

您可以使用 c5> 将用户输入从字符串转换为浮点数:

You can use the input() function to prompt the user for input, and float to convert the user input from a string to a float:

x1 = float(input("x1: "))
y1 = float(input("y1: "))
x2 = float(input("x2: "))
y2 = float(input("y2: "))

如果您使用的是python 2,请使用 raw_input() 代替.

If you're using python 2, use raw_input() instead.

这篇关于如何在python中进行简单的用户输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆