Python Forum
Programming (identifier, literal and function call)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Programming (identifier, literal and function call)
#3
input returns a string

float returns a floating point number for the string

round returns the integer obtained by rounding the floating point number

print displays the integer

You should enter a program that contains this one example line and experiment with it before you write the program for this quiz. Experiment by removing one or more of the function calls to see how these functions work (or generate semantic errors), depending on the types of their argument objects.

When you enter your program and run it, the input for one test case will be entered automatically.

When your program is tested, we will always enter valid integers.
input('Enter a decimal number >')
float('text')
Error on line 2:
float('text')
ValueError: could not convert string to float: 'text'

Thank you so much for your reply... I start to make sense of it. But I don't think I can do it on one line. the program wants me to display it like this:
For example, here are some sample program runs:
Enter an integer >45
45
Enter it again >45
0b101101

I could but it reported an error again because I did not implemented the bin function on the same line I guess.
What is the order to implement the function bin in this line? Still don't understand.


tip:

Recall that you can apply a function to the result of a function as many times as you like, for example, to print the rounded value of a floating point number that is input as a string, you can use this expression:
print(round(float(input('Enter a decimal number >'))))

So this is the code I write to get this result:

print(round(float(input('Enter an integer >'))))
int(round(float(input('Enter it again >'))))
bin(45)

The result is corresponding to the answer:
Enter an integer >45
45
Enter it again >45
0b101101

But when I run it I get this error:
Incorrect Response

#TEST 1#
inputs:
45
45

outputs:
Enter an integer >
45
Enter it again >
** ERROR ** no line
* EXPECTED * 0b101101
----------
#TEST 2#
inputs:
-20
-20

outputs:
Enter an integer >
-20
Enter it again >
** ERROR ** no line
* EXPECTED * -0b10100
----------
#TEST 3#
inputs:
256
256

outputs:
Enter an integer >
256
Enter it again >
** ERROR ** no line
* EXPECTED * 0b100000000
----------
Reply


Messages In This Thread
RE: Programming (identifier, literal and function call) - by ledangereux - Aug-19-2018, 07:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  can you call a function from a list? KEYS 20 6,322 Nov-10-2020, 06:36 PM
Last Post: KEYS
  Verilog HDL Programming to Python Programming? noobcoder 1 3,060 Jul-18-2019, 09:28 PM
Last Post: nilamo
  Calling function-- how to call simply return value, not whole process juliabrushett 2 3,238 Jul-01-2018, 01:17 AM
Last Post: juliabrushett
  Function call Antonio_Gallardo 3 3,226 Dec-29-2017, 11:13 PM
Last Post: Larz60+
  Error is function call Oracle_Rahul 2 3,178 Sep-21-2017, 06:04 PM
Last Post: nilamo
  Call a code written in Fortran programming language in RhinoPython. TOM 2 4,611 Oct-17-2016, 09:29 AM
Last Post: TOM

Forum Jump:

User Panel Messages

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