A
A
azzzriei2020-07-30 17:16:51
Python
azzzriei, 2020-07-30 17:16:51

Python code is not working correctly, what's wrong?

This is a program for simplified creation of a .bat file that creates a matrix effect in cmd. The bottom line is that it seems to work and create a batch file, but inside it is absolutely empty. Help me decide!!

print('Привет я программа которая создаёт эффект матрицы')
batname = input('Как назовём твой софт?')

print('Какого цвета будет текст?')
cvet = input('1:Белый, 2:Зелёный, 3:Голубой, 4:Красный, 5:Жёлтый')

text = input('Введи текст который должен плыть по экрану...Для вывода рандомных цифр введи 1488')

Cvet = ()
Text = ()

#назначение цвета           
if cvet == "1":
             Cvet = str('color f')
             
if cvet == "2":
             Cvet = str('color a')

if cvet == "3":
             Cvet = str('color b')

if cvet == "4":
             Cvet = str('color c')
             
if cvet == "5":
             Cvet = str('color e')
#Назначение текста
if text == "1488":
    Text = "%random% %random% %random% %random% %random% %random% %random% %random%"
else:
    Text = text
       
#Добавление в файл
file = open(r"programm" + '.bat', 'w')
lines = [str(Cvet), str(Text)]
file.write(lines + '\n' )
file.close()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
n_xxx, 2020-07-30
@azzzriei

#Write to file

file = open(batname + '.bat', 'w')
file.write(Cvet + '\n' + Text)
file.close()

S
soremix, 2020-07-30
@SoreMix

Have you tried running the script at all? He falls into error.

Traceback (most recent call last):
File "app.py", line 6, in
file.write(lines + '\n' )
TypeError: can only concatenate list (not "str") to list

1. You cannot add a list and a string
2. You cannot write a list to a file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question