当前位置:   article > 正文

python输出字符串代码_[process completed (signal 6) - press enter]

[process completed (signal 6) - press enter]

正确例题
#!/usr/bin/python3

import time

t = time.localtime(time.time())
localtime = time.asctime(t)
str = “当前时间:” + time.asctime(t)

print(str);

正确例题
for i in range (1,10): #两个循环知1-9 与 1-9相乘
for j in range(1,10):
print(j,“x”,i,"=",i*j,"\t",end="")#输出,道\t是输出后带tab空隔回,end="",表示不断行
if i==j: #该换行答了
print("") #输出空
break #换行

正确例题
str1 = ‘abcdef’
str2 = str1.replace(‘a’,‘1’).replace(‘b’,‘2’)
print(str2)

正确例题
for i in range(1,10):
for j in range(1,10):
print("%s × %s = %s" % ( i ,j , i*j ))

正确例题
str1 = ‘abcdef’
print(str1)

正确例题
import re
string=“A1.45,b5,6.45,8.82”
print (string)

正确例题
import re
a = “aa,ab,ba,bb”
b = a.replace(“a”,“0”).replace(“b”,“1”)
print(b)

正确例题
import random
import string
z= [“a”, “b”, “c”]
n=random.randint(0,len(z))
m=random.randint(0,len(z))
print(z[n],z[m])

正确例题
import random
import string
z= [“a”, “b”, “c”]
n=random.randint(0,len(z))
print(z[n])

正确例题
import random
s = “1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+=-”
n=random.randint(0,len(s))
print(s[n])

正确例题
import random
str1=‘this_a_string_with_several_characters’
n=random.randint(0,len(str1))
print(str1[n])

正确例题
import random
lst=[0,1,2,3,4,5,6,7,8,9]
for i in range(5):
a=random.choice(lst)
lst.remove(a)
print(a,lst)

正确例题
import random
lst=[0,1,2,3,4,5,6,7,8,9]
for i in range(5):
a=random.choice(lst)
lst.remove(a)
print(a)

正确例题
import random
z = [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]
for i in range(0,5):
a=random.choice(z)
z.remove(a)
print(a)

正确例题
import random
z = [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]
for i in range(0,3):
a=random.choice(z)
z.remove(a)
print(a)

正确例题
import random
z = [“鼠”,“牛”,“虎”,“兔”,“龙”,“蛇”,“马”,“羊”,“猴”,“鸡”,“狗”,“猪”]
for i in range(0,5):
a=random.choice(z)
z.remove(a)
print(a)

正确例题
import random
z = [“鼠”,“牛”,“虎”,“兔”,“龙”,“蛇”,“马”,“羊”,“猴”,“鸡”,“狗”,“猪”]
n=random.randint(0,len(z))
print(z[n])

正确例题
import random
z = [“鼠”,“牛”,“虎”,“兔”,“龙”,“蛇”,“马”,“羊”,“猴”,“鸡”,“狗”,“猪”]
n=random.randint(0,11)
print(z[n])

正确例题
import random
z = [“鼠”,“牛”,“虎”,“兔”,“龙”,“蛇”,“马”,“羊”,“猴”,“鸡”,“狗”,“猪”]
n=random.randint(0,len(z))
m=random.randint(0,len(z))
print(z[n],z[m])

正确例题
import random
z=[0,1,2,3,4,5,6,7,8,9]
a=random.choice(z)
print(a)

正确例题
import random
z= [“a”, “b”, “c”]
a=random.choice(z)
print(a)

正确例题
import random
z = [“鼠”,“牛”,“虎”,“兔”,“龙”,“蛇”,“马”,“羊”,“猴”,“鸡”,“狗”,“猪”]
a=random.choice(z)
b=random.choice(z)
print(a,b)

正确例题
import re
m = [“a”, “b”, “c”]
for i in range(0,3):
for j in range(0,3):
print("%s%s" % ( m[i],m[j]))

aa
ab
ac
ba
bb
bc
ca
cb
cc

[Process completed - press Enter]

正确例题
import re
a=“0”
b=“1”
print(a+b)

m = [“a”, “b”, “c”]
print(m)

正确例题
import re
z = [“a”, “b”]
for i in range(0,2):
for j in range(0,2):
print("%s%s" % ( z[i],z[j]))

aa
ab
ba
bb

[Process completed - press Enter]

正确例题
import re
z = [“a”, “b”]
for i in range(0,2):
for j in range(0,2):
for k in range(0,2):
print("%s%s%s" % ( z[i],z[j],z[k]))

aaa
aab
aba
abb
baa
bab
bba
bbb

[Process completed - press Enter]

正确例题
import re
z = [“a”, “b”, “c”]
for i in range(0,3):
for j in range(0,3):
print("%s%s" % ( z[i],z[j]))

正确例题
import re
z = [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]
for i in range(0,2):
for j in range(0,2):
print("%s%s" % ( z[i],z[j]))

00
01
10
11

[Process completed - press Enter]

正确例题
import re
z = [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]
for i in range(0,2):
for j in range(0,2):
for k in range(0,2):
print("%s%s%s" % ( z[i],z[j],z[k]))

000
001
010
011
100
101
110
111

[Process completed - press Enter]

正确例题
import re
z = [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]
for i in range(0,3):
for j in range(0,3):
print("%s%s" % ( z[i],z[j]))

00
01
02
10
11
12
20
21
22

[Process completed - press Enter]

正确例题
import re
z = [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]
for i in range(0,3):
for j in range(0,3):
for k in range(0,3):
for l in range(0,3):

                    for m in range(0,3):
                        for n in range(0,3):


                            print("%s%s%s%s%s%s" % ( z[i],z[j],z[k],z[l],z[m],z[n]))
  • 1
  • 2
  • 3
  • 4
  • 5

正确例题
import random
z = [‘0’,‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’,‘8’,‘9’]
a = random.sample(z,2)
print(a)

正确例题
import random
z = [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]
a = random.sample(z, 1)
print(a)

正确例题
import random
z = [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]
a = random.sample(z,2)
print(a)

正确例题
import random
z = [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]
a=random.choice(z)
print(a)

print(\033[显示方式;字体颜色;背景色m输出内容\033[0m)

其中显示方式、字体颜色、背景色可以缺省

显示方式:0默认 1粗体 4下划线 5闪烁 7反白显示

字体颜色:30黑色 31红色 32绿色 33黄色 34蓝色 35紫色 36青色 37白色

背景色: 40黑色 41红色 42绿色 43黄色 44蓝色 45紫色 46青色 47白色

输出不同颜色字体
print("\033[6;40;51m\t’颜色’\033[0m")
print("\033[8;42;53m\t’颜色’\033[0m")
print("\033[10;44;55m\t’颜色’\033[0m")

print("\033[2;40;51m\t’颜色’\033[0m")
print("\033[3;41;53m\t’颜色’\033[0m")
print("\033[4;42;55m\t’颜色’\033[0m")

print("\033[5;43;51m\t’颜色’\033[0m")
print("\033[6;44;53m\t’颜色’\033[0m")
print("\033[7;45;55m\t’颜色’\033[0m")

print("\033[8;46;51m\t’颜色’\033[0m")
print("\033[9;47;53m\t’颜色’\033[0m")
print("\033[10;48;55m\t’颜色’\033[0m")

通过用户输入数字计算阶乘

获取用户输入的数字

num = int(input("请输入一个数字: "))
fac = 1

查看数字是负数,0 或 正数

if num < 0:
print(“抱歉,负数没有阶乘”)
elif num == 0:
print(“0 的阶乘为 1”)
else:
for i in range(1,num + 1):
fac = fac*i
print("%d 的阶乘为 %d" %(num,fac))

外层for循环代表打印9行

for i in range(1, 10):
# 内层for循环打印列
# 第一行1列,第而行2列,以此类推
for j in range(1, i+1):
# 格式化 输出{行}x{列}={行乘列}
print("{}x{}={} “.format(j, i, i*j), end=”")
print()

用open函数,创建一个输出文件:
os.mkdir(“test.txt”)
然后用打开文件方法w+ :
f = open(test.txt,‘w+’)
在f.write(字符串+’ \n’)

育知同创教育
2017-08-26 · 百度知道合伙人官方认证企业
关注
f = open(‘log.txt’,‘w’)
print(‘日志文件’,file=f) #print到文件
只要你把log.txt的路径写对就可以print到文件了
3 评论 分享 举报

a = input(“请输入:”)
f = open(joinPath(‘log.txt’),‘w’)
print(‘把我在命令行输入的输出到txt:’+a,file=f) #print到文件

输出的时候将print换成写入文件方式

fout = open(“a.txt”, “w+”, encoding=“utf-8”)
fout.write(“this string will be output in txt.”)
1 评论 分享 举报

把结果赋值给变量 content
f = open(“text.txt”,‘wb’)
f.write(content)
f.close()
或者将结果输出,在运行时 python test.py >./test.txt 重定向输出结果。

用python写代码生成一个txt文件
 我来答 分享 举报
2个回答#热议# 意大利和韩国运动员对立的原因是什么?
乔布斯的同学
2016-11-13 · TA获得超过4150个赞
关注
1
2
with open(‘text.txt’,‘w’) as text:
text.write(‘hello’)
4 评论 分享 举报
砍侃看
2016-11-13 · TA获得超过6043个赞
关注
1
2
3
f=open(r"c:\a.txt",‘w’)
f.write(“hello”)
f.close()
3 评论 分享

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/585001
推荐阅读
相关标签
  

闽ICP备14008679号