Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework Help
#1
Hey guys, I'd appreciate some help on a homework question. It's very entry level and not too hard but due to my lack of any knowledge using python and my teacher poorly explaining anything, I just can't figure it out. Thank you!

##1. Write an if statement that assigns 20 to the variable y, and assigns 40 to the variable z
## if the variable x is greater than 100.
## Solution:
##if x > 100:
## y = 20
## z = 40
####1.1. Further extension of 1:
##Using input('Enter integer x: ') prompt:
## Write an if statement that prints and calculates this line:
## distance from x to 100: x - 100 and distance from x to 200: 200 - x
## if the variable x is greater than 100 and less than 200. If not 100<x<200
## do not print anything.
## Write your code here: (start with input)
Reply
#2
What have you tried? We're not big on writing code for people here, but we would be happy to help you fix your code when you run into problems. When you do run into problems, please post your code in Python tags, and clearly explain the problem you are having, including the full text of any errors.

I gotta say, your teach gave you a lot of help here. You have an example, the input call to use, and the condition for the if statement. Use what's there, write some code, and we can help from there.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
I just don't know where to begin. My professor has added some assistance there in the beginning, but without any proper teaching in class, I have no idea where to begin on this assignment. If I could just be pointed in the right direction that would help a lot.
Reply
#4
Hey guys, my friend is helping me with my homework. However he's familiar with C not python. We have figured out the assignment but now we need it converted to python.

int main(){

int x, a, b;

printf("Enter Integer x: \n");
scanf("%d", &x);

if(x > 200 || x < 100)
{
return 0;
}

a = 100 - x;
b= x - 200;

printf("x is %d from 100 and %d from 200.", &a, &b);

return 0;
}
Reply
#5
don't you think that writing your program in python instead of converting from C would be more beneficial for you?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
Obviously... my friend is just trying his best to help. However he is only fluent in C and Java, so he is just trying his best to put it on "paper" so theres something we can work off of.
Reply
#7
You can work from your assignment. Using C as intermediate language will only confuse you more given you are inexperienced. Python is know to be easy for introduction to programming. It's very simple assignment. Look at your notes and think what you are required to do.
And note that giving negative rep to people who are here to help is bad idea
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
Also, instead of getting someone to essentially do the task for you (albeit in another language), since you say your teacher isn't too good, you could have tried looking for other sources of information on how the language works (if statements in particular). Surely you were recommended a book or two to get at least?
Reply


Forum Jump:

User Panel Messages

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