Python Forum
While loop variable defining
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While loop variable defining
#1
Hey guys I want to create something like a database here is my code
i=0
#f=open('t.txt', 'w')
#f.write('Hello')
while True:
name=input('Name ')
if name=='stop':
break
age=input('age ')
car=input('car ')
salary=input('Salary ')
adress=input('Address ')
personality=input('persnality ')
l=[i, [name, age, car, salary, adress, personality]]
#f.write(l)
print(l)
i=i+1
Reply
#2
Hello, please edit your post so that Python code is included in Python code tags. And when you copy code, use shift+ctrl+v so that indentation is preserved.
Reply
#3
You also need to ask a question. What are you trying to do, what isn't working right, what is it doing instead or what error messages are you getting?
Reply
#4
 i=0
#f=open('t.txt', 'w')
#f.write('Hello')
while True:
     name=input('Name ')
     if name=='stop':
         break
     age=input('age ')
     car=input('car ')
     salary=input('Salary ')
     adress=input('Address ')
     personality=input('persnality ')
     l=[i, [name, age, car, salary, adress, personality]]
     #f.write(l)
     print(l)
     i=i+1
      

Im trying to use while loop to define some variables and then i need some sort of access to them maube with the .index or something elss
Reply
#5
(Jan-04-2018, 04:14 PM)j.crater Wrote: And when you copy code, use shift+ctrl+v so that indentation is preserved.
Just some info there is no longer need to use shift+ctrl+v after the changes we done to editor.
Indentation will now always be preserved if user have indentation from start.
You can just look at his first post with edit post and see that indentation is there,
but missing code tag so then do not indentation show in post.
Reply
#6
https://docs.python.org/3/tutorial/datastructures.html
https://docs.python.org/3/library/collec...namedtuple
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable definitions inside loop / could be better? gugarciap 2 451 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,771 Nov-07-2023, 09:49 AM
Last Post: buran
  Nested for loops - help with iterating a variable outside of the main loop dm222 4 1,605 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  loop (create variable where name is dependent on another variable) brianhclo 1 1,149 Aug-05-2022, 07:46 AM
Last Post: bowlofred
  Multiple Loop Statements in a Variable Dexty 1 1,214 May-23-2022, 08:53 AM
Last Post: bowlofred
Big Grin Variable flag vs code outside of for loop?(Disregard) cubangt 2 1,190 Mar-16-2022, 08:54 PM
Last Post: cubangt
  How to save specific variable in for loop in to the database? ilknurg 1 1,160 Mar-09-2022, 10:32 PM
Last Post: cubangt
  How to add for loop values in variable paulo79 1 1,462 Mar-09-2022, 07:20 PM
Last Post: deanhystad
  Using Excel Cell As A Variable In A Loop knight2000 7 4,149 Aug-25-2021, 12:43 PM
Last Post: snippsat
  Using Excel Cell As A Variable In A Loop knight2000 7 5,051 Jul-18-2021, 10:52 AM
Last Post: knight2000

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020