Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I am trying to write pseudocode; however, I don't understand how calling variables work in Python. My goal is to ask a user to enter a string, which I would like to store as a variable. The caveat is the user's entry is the variable that I would like to store as. Is there a way to use that user's entry and somehow call it later? I think I kind of just answered my own question, but I am curious to know what is possible.

Second part to this problem is if I am creating an iteration, such as a 'for' loop, which repeats x number of times as determined by a user's input (input x times to repeat loop), how can a variable be assigned if there are x number of loop iterations? Is there a way to program Python to assign a number to the variable based on the number of iterations, and then use that code to define the variable? I think I just answered my own question again. However, I am not sure. Thanks in advance for any help with this.
Start here:
You can access a variable using the string of a variable's name. However, this is no recommended. It would be much better to use a dictionary with keys that are strings.

I don't understand your second question. Can you provide an example?
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

I am attempting to obtain the weighted grade categories and their weight value; however, the number of categories are not defined (no pun intended). This means that the iteration will loop based on the number input by the user. For example, the program will ask "how many categories?". If the user indicates 5 categories, then I want the program to create 5 variables for those categories. If the user input 9 categories, then there will need to be 9. My question is there a way to program these variables based on the number of categories without having a fixed number of variables. I can easily tell my basic program to have 5 variables in a somewhat static state, but what if the weighted categories are 9, instead of 5. Hope this helps to understand my problem.

Sorry I cannot produce any code, because I haven't written the code yet...I am only in my 4th week of learning Python...professor is asking to develop pseudo code for calculating weighted grades; however, I cannot get to the next step in my planning if I don't understand the constraints of the language.

Something just came to me. Can I build a loop that has a range of available variables, for example a-z, and assign those variables to the user-input categories based on a number input by the user?

For example -

pseudo code:
define a-z as available variables

input "How many categories?"

#User inputs x number of categories

#x of the range of variables are assigned to the user input categories

What do you think?

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)