Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Input function
#1
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 ?
Reply
#2
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.
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
#3
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. >>>
Reply
#4
(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
Reply
#5
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.
buran likes this post
Reply
#6
What is base(10) supposed to do?
Reply
#7
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.
Reply
#8
Thank you everybody !
Reply
#9
(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!
Reply
#10
(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 question
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to print the docstring(documentation string) of the input function ? Kishore_Bill 1 3,550 Feb-27-2020, 09:22 AM
Last Post: buran
  Writing a function that changes its answer based on user input SirRavenclaw 2 2,816 Dec-21-2019, 09:46 PM
Last Post: Clunk_Head
  New to Python - tiny coding assistance on user input function and assign to variable Mountain_Duck 1 2,514 Mar-23-2019, 06:54 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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