Can anyone explain how to store a string as a variable?

Click For Summary
SUMMARY

The discussion focuses on how to enhance user prompts in programming by using descriptive strings instead of single-letter variables. The user aims to replace prompts like "p" with more informative strings such as "Present value?" to improve the clarity of their finance-related calculations. Suggestions include using a print statement before each prompt or checking if the prompt command supports string parameters. The conversation highlights the importance of user-friendly interfaces in programming for better readability and usability.

PREREQUISITES
  • Basic understanding of programming concepts
  • Familiarity with variable assignment in programming
  • Knowledge of prompt commands in programming languages
  • Experience with mathematical calculations in code
NEXT STEPS
  • Explore how to implement user-friendly prompts in Python using the input() function
  • Learn about string manipulation and variable assignment in programming languages
  • Investigate the syntax and features of the specific calculator or programming environment being used
  • Study best practices for creating readable and maintainable code in finance applications
USEFUL FOR

Students in programming or finance courses, educators teaching coding concepts, and developers looking to improve user interaction in their applications.

breebreebran
Messages
12
Reaction score
0
I don't have any big programs. I just write programs to get me through my math classes.
But I want to have the output look pretty.
Like one program I have is for my finance class.

Code:
prompt p
if p = 1
then
Prompt b,r,n,t
r/100→x
b/(1+x/n)^(n*t)→l
disp l
else
Prompt b,r,n,t  
r/100 → x  
b*(x/n)/((1+x/n)^(n*t)-1) → m  
disp m

But what I want to do is instead of prompting p, I want to prompt "present value?"
Then If present value = 1 then etc.
It just looks neater if it prompts an entire string instead of one letter.
So instead of prompting b,r,n,t it'll prompt
"Ending Balance?"
"Rate?"
"Number of compounds?"
"Time?"
And then I can save those strings as variables.
So ending balance → b
Rate → r
Number of compounds → n
And then just have the rest of the program work with those letters instead of having to type out (rate/numberofcompounds)
Every time I try to use strings instead of letters it always gives me a syntax error.
Any help?
 
Computer science news on Phys.org
Well you put a print statement in front of each prompt.
 
breebreebran, you didn't say what kind of calculator you have, which would be useful information. It's possible that the prompt command has an optional first parameter of a string, like this:
prompt "Present value? ", p

If not, do as jedishrfu suggests, and print the string before executing the prompt.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
11K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
10K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
12
Views
3K
  • · Replies 0 ·
Replies
0
Views
4K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 34 ·
2
Replies
34
Views
4K
  • · Replies 9 ·
Replies
9
Views
2K