A
A
Andrey Godunko2021-08-15 13:47:06
Python
Andrey Godunko, 2021-08-15 13:47:06

Why, after adding to the variable, the text. Append text not showing up?

When i run the code. Then in a loop that repeats 3 times, the text is not added to the variable . There are no errors.
I hope I explained briefly and clearly.

import os

goal = str(input('Веди цель  >> '))
goal_1 = str(input('Веди цель  >> '))	
goal_2 = str(input('Веди цель  >> '))
goal_3 = str(input('Веди цель  >> '))

if goal_3 =='all':
  for i in range(3):
    text = ' *respect'
    a = ( f'1. {goal}' ) 
    b = (  f'2. {goal_1}' )
    c = ( f'3. {goal_2}' )
    print(a)
    print(b)
    print(c)
    what = str(input('И так какую цель ты виполнил 1, 2, 3 ? >> '))

    if what == '1':
      os.system('cls||clear')# clean cmd
      a += text

    elif what == '2':
      os.system('cls||clear')# clean cmd
      b += text

    elif what == '3':
      os.system('cls||clear')# clean cmd
      c += text

    else:
      print( 'Так что-то пошло не так.' )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Prometheus, 2021-08-15
@Noy-name-boy

My regards! )
Could you clarify the question - what exactly do you expect from this cycle.
As far as I understand
, on each of the 3 iterations of the loop, at the beginning, all variables are designated accordingly (a = ..., b = ..., etc.)
Then, depending on the value of the what variable, one variable is modified by assigning a string stored in text variable
If you put print(a + " " + b+ " " + c) in the for block at the end of the above code, you will see that the required variable is modified properly (*respect appears at the end of one of the lines). Then the iteration ends and the SAME variables (a, b, c) are again put into the SAME values ​​as at the beginning of the previous loop (and they are also displayed, most likely, therefore you do not see that the variables are being modified)
If the problem is not in this, please clarify your question.
Andrey Godunko ,
You need something like the following:

import os

goal = str(input('Веди цель  >> '))
goal_1 = str(input('Веди цель  >> '))
goal_2 = str(input('Веди цель  >> '))
goal_3 = str(input('Веди цель  >> '))

if goal_3 =='all':
  text = ' *respect'
  a = ( f'1. {goal}' )
  b = (  f'2. {goal_1}' )
  c = ( f'3. {goal_2}' )
  for i in range(3):
    print(a)
    print(b)
    print(c)
    what = str(input('И так какую цель ты выполнил 1, 2, 3 ? >> '))

    if what == '1':
      os.system('cls||clear')# clean cmd
      a += text

    elif what == '2':
      os.system('cls||clear')# clean cmd
      b += text

    elif what == '3':
      os.system('cls||clear')# clean cmd
      c += text

    else:
      print( 'Так что-то пошло не так.' )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question