0

I'm trying to do a simple python program able to print the right variable depend of the incremented value.

a1 = 'hiya'
a2 = 'i love cats'

lignenum = 2
incremented_value = 1
while incremented_value <= lignenum:
    print(a, incremented_value) 
     incremented_value += 1 

i want my program to render :

'hiya' 'i love cats'

Thanks for reading me

3
  • Where is a and p defined? Commented Nov 27, 2019 at 17:01
  • sorry p is incremented value Commented Nov 27, 2019 at 17:02
  • My true program have many more variable to print ^^^ Commented Nov 27, 2019 at 17:14

2 Answers 2

1

I would define a list with this values you would like to print, and then access them according to their index-value. That is:

arguments = ['hiya','i love cats']
lignenum = 1
incremented_value = 0
while incremented_value <= lignenum:
    print(arguments[incremented_value]) 
    incremented_value += 1 

This prints:

hiya
i love cats
Sign up to request clarification or add additional context in comments.

Comments

1

Use a list and iterate btween 0 and the length of the list. There are better ways to do this but a simple solution is below

a = []
a.append('hiya')
a.append('i love cats')

lignenum = len(a)
incremented_value = 0
while incremented_value <= lignenum:
    print(a[incremented_value]) 
     incremented_value += 1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.