Posts: 5
Threads: 2
Joined: Dec 2020
Hi everybody !
I need your help about two exercises I don't know how to do them:
1) Use the input() function and the print() procedure to write a program that requests data, calculates and prints the area of a triangle
2) Use the input() function to request the data needed to plot geometric figures using procedures defined with the turtle commands
Can you help me please ?
Posts: 8,168
Threads: 160
Joined: Sep 2016
Dec-19-2020, 11:28 AM
(This post was last modified: Dec-19-2020, 11:28 AM by buran.)
What have you tried? We are glad to help, but we are not here to do your homework for you. Read Homework and No Effort Questions
Please, post your code (in code tags) and ask specific questions. Don't forget to include the full traceback (in error tags) if you get one.
Posts: 1,358
Threads: 2
Joined: May 2019
If you don't know where to start, try the help command in IDLE.
Output: >>> help(input)
Help on built-in function input in module builtins:
input(prompt=None, /)
Read a string from standard input. The trailing newline is stripped.
The prompt string, if given, is printed to standard output without a
trailing newline before reading input.
If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
On *nix systems, readline is used if available.
>>> help(print)
Help on built-in function print in module builtins:
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
>>>
Posts: 5
Threads: 2
Joined: Dec 2020
(Dec-19-2020, 11:28 AM)buran Wrote: What have you tried? We are glad to help, but we are not here to do your homework for you. Read Homework and No Effort Questions
Please, post your code (in code tags) and ask specific questions. Don't forget to include the full traceback (in error tags) if you get one.
One I tried is this one:
def mytriangle (base, height):
print ("The base is ", base)
print ("The height is ", height)
base (10)
height (15)
myarea = base * height / 2
This function gives me error
Posts: 1,838
Threads: 2
Joined: Apr 2017
It would really help if you followed the instructions buran gave you above, specifically posting your code within code tags and posting the full traceback. Remember we can't see your screen.
Posts: 1,358
Threads: 2
Joined: May 2019
What is base(10) supposed to do?
Posts: 1,950
Threads: 8
Joined: Jun 2018
Dec-21-2020, 07:59 AM
(This post was last modified: Dec-21-2020, 07:59 AM by perfringo.)
jefsummers provided way to learn definitions of functions you need to use. This is valuable knowledge - how to access built-in help of Python. It takes some practice to develop skills for comprehending information which help provides (and this is what learning is all about).
It seems to me that some examples how to use input() can help in learning process. In interactive interpreter:
>>> input('What is your name? ') # ask for name
What is your name? Bob # input the name
'Bob' # name is displayed but it's gone after that
>>> name = input('What is your name? ') # in order to use name later, we assign it to name
What is your name? Bob
>>> name # now we can use name whenever we need
'Bob'
>>> profession = input('What is your profession? ') # let' ask some more and assign
What is your profession? The Builder
>>> profession
'The Builder'
>>> title = f'{name} {profession}' # let's use these values to create new value
>>> title
'Bob The Builder' Just keep in mind that input always returns str, so if you want to make calculations conversion is needed.
jefsummers and soupworks like this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Posts: 5
Threads: 2
Joined: Dec 2020
Posts: 3
Threads: 1
Joined: Dec 2020
(Dec-19-2020, 05:40 PM)Fabio87 Wrote: (Dec-19-2020, 11:28 AM)buran Wrote: What have you tried? We are glad to help, but we are not here to do your homework for you. Read Homework and No Effort Questions
Please, post your code (in code tags) and ask specific questions. Don't forget to include the full traceback (in error tags) if you get one.
One I tried is this one:
def mytriangle (base, height):
print ("The base is ", base)
print ("The height is ", height)
base (10)
height (15)
myarea = base * height / 2
This function gives me error here you have some problems.
in print() u have to use f string or convert it. also its not necessary to define the variables base and height there!
Posts: 2
Threads: 0
Joined: Jan 2021
(Dec-19-2020, 11:16 AM)Fabio87 Wrote: Hi everybody !
I need your help about two exercises I don't know how to do them:
1) Use the input() function and the print() procedure to write a program that requests data, calculates and prints the area of a triangle
2) Use the input() function to request the data needed to plot geometric figures using procedures defined with the turtle commands
Can you help me please ? simply google your quest ion
|