Python Forum
Begining Python classlab help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Begining Python classlab help
#1
Hi all, (questions to do with IF, while functions)
I am taking a beginning python coding class for arcgis and am having some trouble figuring out two of my lab questions. I have never done any coding before beside R but I do not think that counts. We are in the first weeks of class and I fully admit I am lost. My teacher isn't very helpful at the current moment, she keeps sending me back to the book which I have reread multiple times.

Question one:
Write a series of Python statements that will prompt the user for three strings. Then, using an if statement, print them in alphabetical order.

what I have so far and have gotten stuck on:

>>> word_1=raw_input ("inset word:")
>>> word_2= raw_input ("insert word:")
>>> word_3=raw_input ("insert word:")
>>> list= (word_1 + word_2 + word_3)
>>> print list

I figured the next thing to do was sort my list but the function keeps throwing an error. I am also unsure how to make this into an IF statement. I figured the first thing I should do is see if I could even make inputs into a list I could sort. Since out reading talked about such things. The reading examples for if statement are all numerical so not sure how it works with non-numerical.

Question two:
Using a while loop, produce a simple table of sines, cosines and tangents. Make the variable x range from 0 to 3 in steps of 0.1. For each value of x, print the value of x, math.sin(x), math.cos(x) and math.tan(x).

if have to admit I am not even sure what this question is asking. I learn best by examples and have no example to how to even approach this. I am not asking for anyone to do the code for me but if someone could send me to an example that is similar to this question that would be amazing
Reply
#2
The following should help you with creating a list from your strings:
https://www.practicepython.org/exercise/...erlap.html

list is a Python built-in-type and should not be used as a variable name. Keywords and Built-in-Types should not be used for variable names. See http://www.pythonforbeginners.com/basics...in-python/ and https://docs.python.org/2/library/functions.html

This should help you with the while loop: http://www.pythonforbeginners.com/loops/...while-loop

for loops are preferred to while loops. For loop range items must be integers. Try something like:
for x in range(0, 31):
  print(x/10, x/10 * x /10)
Output:
(0.0, 0.0) (0.1, 0.01) (0.2, 0.04) (0.3, 0.09) ... (2.8, 7.84) (2.9, 8.41) (3.0, 9.0)
Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply


Forum Jump:

User Panel Messages

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