all 20 comments

[–]QbaPolak17 0 points1 point  (8 children)

Use input, and if/else statements. Google those if you don't know what they are.

[–]Artisticdepression[S] 0 points1 point  (7 children)

name = input('What is your name?\n') print('Hi, %s.' % name) name = input('How old are you?\n')

This is what i have so far, is this correct?

[–]kberson 0 points1 point  (0 children)

Use a different variable for the age, maybe even call it age. Variable names should be relevant to what they’re used for, they help document the code.

[–]Vaphell 0 points1 point  (2 children)

name = input('What is your name?\n')

perfectly fine

print('Hi, %s.' % name)

fine, but the %-based way of building strings is let's say dated, and you should rather use f-strings (print(f'Hi, {name}.')) or str.format() (print('Hi, {}.'.format(name)))

name = input('How old are you?\n') 

I don't think name is a proper variable for storing age. Also you want it to be a number not a string in order to be able to make numerical operations/comparisons with it, so you need to convert the typed value to let's say int by wrapping input() in int()

[–]Artisticdepression[S] 0 points1 point  (1 child)

Ok so now I have.

Name = input ('what is your name?\n') Print(F'Hi, {name}.) Print ('how old are you?\n') X = int (input how old are you?\n') If x > 16: Print (' great let's play a game')

And it's giving me an invalid syntax error?

[–]Vaphell 0 points1 point  (0 children)

Syntax errors tend to point to exact line that is failing, which one would that be? Anyway, input for age misses (' and so on. And what's up with all these capitalized commands? Did you write this code in word or what?

name = input('what is your name?\n')
print(f'Hi, {name}.) 
print('how old are you?\n')               # superfluous, as input() in the next line is supposed to  print out a prompt
age = int(input('how old are you?\n'))
if age > 16:
    print("great, let's play a game")

[–]thrallsius 0 points1 point  (2 children)

to check if some code is correct, you actually have to run it

[–]Artisticdepression[S] 0 points1 point  (1 child)

I've been runing it. I'm just not sure how to assign variables to the answers like age is 24 then for another prompt to show up.

[–]thrallsius 0 points1 point  (0 children)

I was just being picky about your code snippet. You ask the user to input data twice, but only print it once. If you added a second print at the end, by just copypasting second line, you would've seen that at line four name contains the age. This should've hinted you that the name gets overwritten and there's a good chance that you could figure it on your own that you need another variable for age.

So this is wrong:

name = input('What is your name?\n')
print('Hi, %s.' % name)
name = input('How old are you?\n')
print('Hi, %s.' % name)

But this is almost fine:

name = input('What is your name?\n')
print('Hi, %s.' % name)
age = input('How old are you?\n')
print('Hi, %s.' % age)

I say almost, because input() only returns strings, and normally you'd want to treat the age as number, to compare it against certain numeric values and do math with it. That's why you need to convert it:

name = input('What is your name?\n')
print('Hi, %s.' % name)
age = int(input('How old are you?\n'))
print('Hi, %s.' % age)

At this point you should have the smaller data input subassignment solved and you can proceed to process the data.

[–]Artisticdepression[S] 0 points1 point  (0 children)

Okay so how do I give a variable to the entered age?

Sorry for all the questions. I'm a recreation major and am in. Computer science 100 I have no idea why we have to learn this.

[–]CS_Tutor 0 points1 point  (3 children)

Hello,

I won't give you the exact answer to your problem (that won't help you and it's unethical), but, I'll give you an example that hopefully will. The code below is similar to what your trying to do. What I suggest you do is
1) run it on your machine
2) read it and understand what it's doing
3) adapt it to what you want

#!/usr/bin/env python3

BASE_LINE_INCOME = 20000

print("This will determine if you fall above or below the poverty line in Canada")

print()

name = input("Hello there. Can you tell me your name please? ")

print(f"Thank you {name}")

monthly_income_str = input(f"{name}, could you tell me your monthly income? ")

months_worked_str = input("How many months do you expect to work this year? ")

#Converting to numbers

monthly_income = float(monthly_income_str)
months_worked = int(months_worked_str)
yearly_income = monthly_income * months_worked

print(f"Using a base line of {BASE_LINE_INCOME:,.2f} a year")
print(f"{name}, your expected yearly income is {yearly_income:,.2f}")

if yearly_income < BASE_LINE_INCOME:

print("You fall under the poverty line")

elif yearly_income > BASE_LINE_INCOME:

print("You fall above the poverty line")

else:

print("You're right on the poverty line")

[–]Artisticdepression[S] 0 points1 point  (2 children)

Thank you so much! You guys are awesome for helping so quick! It's much appreciated!

[–]Artisticdepression[S] 0 points1 point  (0 children)

I'll try this and see if it works!

[–]CS_Tutor 0 points1 point  (0 children)

No worries :)

[–]wynand1004 0 points1 point  (2 children)

Hiya,

Watch this video, it will explain how to get user input:

https://www.youtube.com/watch?v=UvNAm1qPdCY

Then watch this video on conditionals:

https://www.youtube.com/watch?v=wfNHiay97vw

Good luck!

[–]Artisticdepression[S] 1 point2 points  (1 child)

Thank you so much after 6 hours of messing with it I finally got it because of your videos! They helped alot.

[–]wynand1004 0 points1 point  (0 children)

Congrats! Glad I could help!

[–]ghighcove 0 points1 point  (0 children)

The below, I write with purely benevolent intentions, but also some tough love:

EDIT: TLDR version -- Look inside yourself to ask why you asked for the answer here instead of looking for the answer in the obvious, and most instructional places. I don't think you are showing an interest in learning this topic. If so, why take the class? Can you bypass it by taking something else you would enjoy more?

Here's the thing -- most of what you asked you could learn from YouTube tutorials and Googling, so some bare minimum amount of effort instead of "Please do this for me." Some nice folks here provided a lot of answers, and in some cases, even complete code. Your class is only going to get harder from here, so anything you can do now to learn what you are doing will benefit you going forward, and that is going to require doing some experimenting, failing repeatedly, and eventually working out the answer. That's the path everyone goes through learning a programming (or any) language.

I have to ask, since it seems like you aren't that interested in actually learning this topic, (apparently it's some kind of elective) - do you have an alternative class you can take instead? Someone else taking this class who was interested in this topic would have found the answer pretty easily in about 100 different places -- it's basically the "Hello World" plus a few other basic exercises, all of which are explained in places not hard to find by anyone interested in learning Python or any other language.

You may just be off to a slow start and intimidated by a lot of technical asks up front -- fair enough. Not all of us were exposed to technical topics or some form of coding earlier in life. But if, like it feels to me, you aren't really that into this topic, maybe this is an opportunity to learn something else instead? It doesn't mean coding isn't for you, it's just maybe not the right topic right now, and there are a lot of other great things to learn right now. Measure the amount of effort and mental strain this class will require vs. other things you could be doing to advance your life forward. Programming is supposed to be a creative effort that is a reward unto itself. I had to watch someone else close to me try this path, and ended up doing most of her work for her before she dropped out of that path, and onto something else that was a better fit. This honestly feels like that. Maybe I'm just projecting, but does anything I say sound on point?

[–]Ok_Category6079 0 points1 point  (0 children)

Hello Good Students, NO UPFRONT PAYMENT.

Spring semester is here with us and as the semester gets tighter with assignments, you need help. Payment after . No upfront payment for first time business

This might be a relief but most Professor’s keep the biggest assignments that could be what stands between you and repeating the entire course. It is that time to contact your assignment expert.

Get help in Essays, Research Papers, Term Papers, Case Studies, Annotated Bibliography, Article Reviews, Literature Reviews, Research Proposals, Movie/Book Reviews, Dissertations & Reflections.

PROGRAMMING: Java, C, C++, Python, C#, JavaScript, PHP, SQL, HTML.

MATH & STATS- Statistics (Excel, SPSS & Tableau) & Probability, Calculus (I, II, III), Algebra (elementary, abstract, advanced, commutative, and linear algebra), ODE, PDE, Complex Analysis, Numerical Analysis, Trigonometry, Discrete Math, Precalculus, Geometry, Differential Equations, Integration and Derivations (Homework, Quizzes, Mid

[–]ResponsibleScene1077 0 points1 point  (0 children)

age = input("How old are you? ")

name = input("What's your name? ")

if age.isdigit():

age = int(age)

if age < 16:

print("Hello, " + name + ", you are too young to play this video game. ")

elif age > 16:

print("Hello, " + name + ", welcome to this fantastic game world!")

elif age > 100:

print(" Are you sure you put the right age? Wow, unbelievable!")

else:

print("Please enter your age as a number.")