js给file类型的input框赋值_数据类型和变量用Python做数学运算

这篇博客介绍了Python中的变量使用,包括变量命名规则和示例。接着讲解了Python中的数字类型和数学运算,包括操作符、表达式以及真除法。然后详细讨论了字符串的运用,如输入输出、字符串连接以及关键字参数`end`的使用。最后提到了如何利用字符串改进彩色螺旋线的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 变量----保存内容的地方

变量名---以字母为开头,其他的字符必须是字母、数字、下划线,区分大小写,中文也可以,但不推荐。

举例

my_name = "Bryson"

my_age = 43

your_name = input("What is your name? ")

your_age = input("How old are you? ")

print("My name is", my_name, ", and I am", my_age, "years old.")

print("Your name is", your_name, ", and you are", your_age, ".")

print("Thank you for buying my book,", your_name, "!")

2. Python中的数字和数学运算

数字类型主要是整数和浮点数(带有小数点的数字)

简单的数据类型:布尔值(Boolean),存储了True或False

操作符:+ 、-、*、 /、 **求幂、 ()分组

表达式:数学题

练习:在命令行中输入数学题,计算结果

语法错误:Syntax Error,语法就是语句要遵守的规则

赋值语句:变量=表达式

真除法:Python的/是真除法,例如5/2=2.5

举例:养成写注释的习惯,程序的步骤够成了算法

# AtlantaPizza.py – a simple pizza cost calculator

# Ask the person how many pizzas they want, get the number with eval()

#eval()字符串变成数字

number_of_pizzas = eval( input("How many pizzas do you want: ") )

# Ask for the menu cost of each pizza

cost_per_pizza = eval( input("How much does each pizza cost: ") )

# Calculate the total cost of the pizzas as our subtotal

subtotal = number_of_pizzas * cost_per_pizza

# Calculate the sales tax owed, at 8% of the subtotal

tax_rate = 0.08 # we store 8% as the decimal value 0.08

sales_tax = subtotal * tax_rate

# Add the sales tax to the subtotal for the final total

total = subtotal + sales_tax

# Show the user the total amount due, including tax

print("The total cost is $", total)

print("This includes $", subtotal, "for the pizza and")

print("$", sales_tax, "in sales tax.")

3. 字符串---Python中真正的字符

# SayMyName.py - prints a screen full of the user's name

# Ask the user for their name

name = input("What is your name? ")

name2 = input("What is your name2? ")

# Print their name 100 times

for x in range(50):

    # Print their name followed by a space, not a new line

print(name,name2,sep='--',end=" rules! ")

关键字参数:end

字符串用双引号或者单引号引起来

4. 用字符串改进彩色螺旋线

3a07a6b49ec5d0e1dfea19ea3eb99638.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值