标签:... insert Python number python Linux print 第五天 tanuki
一、格式化打印
# 将信息打印
------------------info of tanuki------------------
Name : Tanuki
email : tanuki_11@163.com
hobby : stars and seas
-----------------------end------------------------
# 开始
In [1]: info = 'info of tanuki'
In [2]: end = 'end'
In [3]: info.center(50,'-')
Out[3]: '------------------info of tanuki------------------'
In [4]: end.center(50,'-')
Out[4]: '-----------------------end------------------------'
In [5]: name = input()
In [6]: name
Out[6]: 'tanuki '
In [7]: email = input("email:")
email:tanuki_11@163.com
In [8]: hobby = input("hobby:")
hobby:stars and seas
In [9]: mes = f'''
...: ------------------info of tanuki------------------
...: Name : {name}
...: email : {email}
...: hobby : {hobby}
...: -----------------------end------------------------
...: '''
In [10]: print(mes)
------------------info of tanuki------------------
Name : tanuki
email : tanuki_11@163.com
hobby : stars and seas
-----------------------end------------------------
二、for循环
# 之前用shell,python分别写了for 和 if 的循环,今天补充一下for循环。
# python 中的for
In [1]: for i in range(10):
...: number = 1
...: a = input("insert a number:")
...: if not a:
...: continue
...: if a == "q":
...: break
...: a = int(a)
...: if a > 1:
...: print("less then 1")
...: elif a < 1:
...: print("more then 1")
...: else:
...: print(f"{a} is right!bingo")
...:
...:
insert a number:1
1 is right!bingo
insert a number:2
less then 1
insert a number:6
less then 1
insert a number:q
# shell脚本中的for
[tanuki@localhost python_study]$ bash for.sh
please insert a number: 1
20 greater then 1
please insert a number: 10
20 greater then 10
please insert a number: 20
the 20 is right!
[tanuki@localhost python_study]$ cat for.sh
#!/bin/bash
# author : tanuki
# using : For loop in shell
a=20
for i in `seq 1 10`
do
read -p "please insert a number: " number
if [ "$a" -lt "$number" ] ;then
echo "$a less $number"
elif [ "$a" -gt "$number" ] ;then
echo "$a greater then $number"
else
echo "the $number is right!"
exit
fi
done
二、判别奇偶数
# shell判断
[tanuki@localhost python_study]$ cat ji_ou_judge.sh
#!/bin/bash
#!/bin/bash
for((i=1;i<=10;i++))
do
a=`expr $i % 2`
if [ "$a" -eq 0 ] ;then
echo "$i 是偶数 "
else
echo "$i 是奇数"
fi
done
[tanuki@localhost python_study]$ ji_ou_judge.sh
1 是奇数
2 是偶数
3 是奇数
4 是偶数
5 是奇数
6 是偶数
7 是奇数
8 是偶数
9 是奇数
10 是偶数
[tanuki@localhost python_study]$
# python判断
[tanuki@localhost python_study]$ ji_ou_judge.py
0是偶数
1是奇数
2是偶数
3是奇数
4是偶数
5是奇数
6是偶数
7是奇数
8是偶数
9是奇数
10是偶数
[tanuki@localhost python_study]$ cat ji_ou_judge.py
#!/usr/bin/env python3
# function about python
#def tanuki():
# print("螃蟹在剥我的壳,笔记本在写我,")
# print("漫天的我落在枫叶上雪花上,")
# print("而你在想我...")
#tanuki()
for i in range(11):
# if i % 2 == 0: #两种写法,不赋值a也可以。
a = i % 2
if a > 0:
print(f"{i}是奇数")
else:
print(f"{i}是偶数")
标签:...,insert,Python,number,python,Linux,print,第五天,tanuki 来源: https://www.cnblogs.com/tanukisama/p/16345668.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。