编程小白的第一本python入门书——学习代码

本书针对编程初学者,详细介绍了Python语言的基础知识和核心概念,包括变量、控制结构、函数、数据结构等内容,旨在帮助新手快速掌握Python编程。
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 21 15:52:54 2019

@author: Administrator
"""

a=12
a
print(a)

num=1
string="1"
num2=int(string)
print(num+num2)

words='words'*3
print(words)

word='a loooooong word'
num=12
string='bang!'
total=string*(len(word)-num)
print(total) 

name='my name is Mike'
print(name[0]) 
print(name[-4])
print(name[11:15])
print(name[5:])
print(name[:5])

phone_number='1386-666-0006'
hiding_number=phone_number.replace(phone_number[:9],'*'*9)
print(hiding_number)

city=input("write down the name of city:")
url="http://apistore.baidu.com/microservice/weather?cityp/inyin={}".format(city)

def fahrenheit_converter(C):
    fahrenheit=C*9/5+32
    return str(fahrenheit)+'°F'
C2F=fahrenheit_converter(35)
print(C2F)

def trapezoid_area(base_up,base_down,height):
    return 1/2*(base_up+base_down)*height
trapezoid_area(1,2,3)
trapezoid_area(base_up=1,base_down=2,height=3)

file = open('/Users/Hou/Desktop/text.txt','w')
file.write('Hello World')

abs(-10) > len('length of this word')

42 > 'the answer'
42 == 'the answer' 
42 != 'the answer'

album=[]
album = ['Black Star','David Bowie',25,True]
album.append('new song')
print(album[0],album[-1])
'Black Star' in album

the_Eddie = 'Eddie'
name = 'Eddie'
the_Eddie == name
the_Eddie is name

1 < 3 and 2 < 5 #True
1 < 3 and 2 > 5 #False
1 < 3 or 2 > 5 #True
1 > 3 or 2 > 5 #False

def account_login():
    password = input('Password:')
    if password == '12345':
      print('Login success!')
    else:
      print('Wrong password or invalid input!')
      account_login()
account_login()

password_list = ['*#*#','12345']
def account_login():
    password = input('Password:')
    password_correct = password == password_list[-1]
    password_reset = password == password_list[0]
    if password_correct:
       print('Login success!')
    elif password_reset:
        new_password = input('Enter a new password:')
        password_list.append(new_password)
        print('Your password has changed successfully!')
        account_login()
    else:
        print('Wrong password or invalid input!')
        account_login()
account_login()

for num in range(1,11): 
    print(str(num) + ' + 1 =',num + 1)

songslist = ['Holy Diver', 'Thunderstruck', 'Rebel Rebel']
for song in songslist:
    if song == 'Holy Diver':
       print(song,' - Dio')
    elif song == 'Thunderstruck':
       print(song,' - AC/DC')
    elif song == 'Rebel Rebel':
       print(song,' - David Bowie')
    
for i in range(1,10):
    for j in range(1,10):
        print('{} X {} = {}'.format(i,j,i*j))    
    
while 1 < 3:
   print('1 is smaller than 3')   
    
count = 0
while True:
   print('Repeat this line !')
   count = count + 1
   if count == 5:
      break  
    
fruit = ['pineapple','pear']
fruit.insert(1,'grape')
print(fruit)   
    
fruit[0:0] = ['Orange']
print(fruit)

periodic_table = ['H','He','Li','Be','B','C','N','O','F','Ne']
print(periodic_table[0])
print(periodic_table[-2])

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值