0

What I want to achieve is something like:

  1. Ask user question: How many cars you have given on rent?
    (this is just a print statement.)

  2. Now user should input from 0 to n. (Only numbers are allowed.)
    (This is user input)
    3

  3. Now this will create 3 variables and for each such created variable it will ask to user to input values. e.g.

    incomeFromCar_1 = 500
    incomeFromCar_2 = 600
    incomeFromCar_3 = 700

Some clarifications:

  • If user input 0, nothing should be done and script should exit out of current lines of code and go to next line of code.
    • ("How many times have you watched Friends? ---> What I mean by this is next line of code is entirely independent of this.)
  • If user input does not input numbers, i.e. any string or even a float (2.25) it should through a error message saying "Please input numbers only".
  • I could have posted a code, but it's only user input & I don't even know what to use for next line of code: i.e. a for or while loop, a dict, or a list?

System Info:

Python Version 3.5
Atom IDE
Windows 7
martineau
  • 119,623
  • 25
  • 170
  • 301
Drp RD
  • 190
  • 1
  • 1
  • 6
  • 2
    and what have you tried so far? – Dimitris Fasarakis Hilliard Dec 17 '16 at 16:49
  • only user input i can't figure out what to do next.....to be honest, I know I am asking for basically entire thing. – Drp RD Dec 17 '16 at 16:55
  • 2
    This is a horrible approach - what possible good would it be to have the user input in variables that don't actually exist in your code? The proper way to handle variable-length input is with a single container variable - probably a list in this case. – jasonharper Dec 17 '16 at 16:57
  • @jasonharper calling it a horrible approach is a bit unfair, OP is clearly very new to programming and hasn't come across things like lists. But yes, a list is the correct thing to use here. – Alex Hall Dec 17 '16 at 17:03
  • 1
    See [_Why you don't want to dynamically create variables_](http://stupidpythonideas.blogspot.com/2013/05/why-you-dont-want-to-dynamically-create.html). – martineau Dec 17 '16 at 17:07
  • 1
    ...to be clear, "please write my program for me" questions are unwelcome here ("too broad" is the official close reason) -- so in marking this a duplicate, I did the courtesy of reading it as a permissibly narrow question, ie. how to dynamically create variables based on a loop. – Charles Duffy Dec 17 '16 at 17:35
  • See http://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions, the answer to which discusses how homework (or homework-style) questions can be asked and answered in a way that's fully compliant with site rules. – Charles Duffy Dec 17 '16 at 17:38

0 Answers0