没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
day1 Printing,Commenting,Debugging,String
Manipulation and Variables(打印、注释、调
试、字符串操作和变量)
Day 1 - Python Print Function
The function is declared like this:
print('what to print')
print("Day 1 - Python Print Function")
print("The function is declared like this:")
print("print('what to print')")
print("Hello" + " " + "Angela")
# SyntaxError IndentationError NameError
# The Python Input Function
print("What is your name?")
input("What is your name?")
print("Hello" + " " + input("What is your name?")) # Hello Tom
# how to get the length of a string in python stack flow
print(len(input("What is your name?")))
>What is your name?AngelaBaby
>10
name = input("What is your name?")
length = len(name)
print(length)
Project_Band Name Generator
day2 Data Types,Numbers,Operations,Type
Conversion,f-Strings(数据类型、数字、运算、
类型转换、f字符串)
# Variables Exercise
a = input("a:")
b = input("b:")
# a,b=b,a
temp=a
a=b
b=temp
print("a="+a)
print("b="+b)
# SyntaxError IndentationError NameError
print("Welcome to the Band Name Generator.")
city_name = input("What's name of the city you grew up in?\n")
pet_name = input("What's your pet's name\n")
print("Your band name could be " + city_name + " "+ pet_name)
Welcome to the Band Name Generator.
What's name of the city you grew up in?
China
What's your pet's name
Robbit
Your band name could be China Robbit
print(len(123)) #TypeError
Data Type Exercise
# Data Type
# String
print("Hello"[0]) # H
print("Hello"[4]) # o
print(type("Hello")) # <class 'str'>
# Integer
print(123 + 456) #579
print(123_456_789_1011_1213) #12345678910111213
# Float
print(3.14159)
# Boolean
True
False
name_char = len(input("What is your name?"))
new_name_char = str(name_char)
print("Your name is " + new_name_char +" characters.")
# Data Type Exercise
numbers = input("Type a two digit number:")
num1 = int(numbers[0])
num2 = int(numbers[1])
result = num1 + num2
print(result)
3 + 5
4 - 2
3 * 2
6 / 3
print(2 ** 3) # 8
print(6 / 3) # 2.0
print(6 // 3) # 2
# PEMDAS
# () ** */ +-
# BMI Calculator
height = input("enter your height in m: ")
weight = input("enter your weight in kg: ")
bmi = float(weight) / (float(height) ** 2)
bmi_as_int = int(bmi)
print(bmi)
print(bmi_as_int)
print(round(8 / 3, 2)) # 2.67
print(8 // 3) # 2
print(type(8 // 3)) # <class 'int'>
score = 0
height = 1.8
isWinning = True
print("your score is " + str(score))
# f-String
print(f"your score is {score},your height is {height},you are
winning is {isWinning}")
# Your Life in Weeks
# 1year=356days 1year=52weeks 1year=12months for exercise
age = input("What is your current age?")
age_as_int = int(age)
year_remaining = 90 - age_as_int
days_remaining = year_remaining * 365
weeks_remaining = year_remaining * 52
month_remaining = year_remaining * 12
print(f"you have {days_remaining} days,{weeks_remaining} weeks,and
{month_remaining} months left.")
print("Welcome to the tip calculator.")
bill = input("What was the total bill? $")
percentage = input("What percentage tip would you like to give? 10
, 12 , or 15?")
people = input("How many people to split the bill?")
bill_as_float = float(bill)
percentage_as_int = int(percentage)
people_as_int = int(people)
total_bill = bill_as_float * (1 + percentage_as_int / 100)
average_bill = total_bill / people_as_int
final_amount = round(average_bill, 2)
final_amount = "{:.2f}".format(final_amount)
print(f"Each person should pay:{final_amount}")
剩余23页未读,继续阅读
资源评论
lalaxuan
- 粉丝: 693
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功