It is currently 18 Oct 2021, 08:41

• Featuring Members' Works (Image Attachments) •
1: member
2: member
3: member
4: member
5: member

GIMP/GL:  Tutorials | Tips | Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | 🡆 Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP
Sponsored content for World Food Program

Input and Number variables Exercise

tim
GL Blogger
1st Place
5541 Post(s)

Input and Number variables Exercise

Post#1 by tim » 16 Nov 2018, 20:23


Write a program that prompts the user for 2 numbers (integers) (a & b).
Then print out: "The product of a & b is: ", then the product of (a&b).
Solution:
Spoiler:

Code: Select all

a = input("Enter a:")
b = input("Enter b:")
a = int(a)
b = int(b)
print ("The product of a & b is: " + str(a*b))
aka Tin
World Food Program | Good Deeds Forum

         

Krikor
Forum Member
12th Place
917 Post(s)

Post#2 by Krikor » 17 Nov 2018, 16:06


Oh my ... I was wrong five hundred times. So easy and yet I had to hammer my head until I could work it out. :hammer_head:

I wanted to put the answer in a single line, but I ended up giving up and using two lines to give the answer. :gaah:

Maybe the beer glasses I took earlier had an effect, but I still hoped it would have been easier to solve that. :drinking_smilies:

Thx Tim. :thumbsup:
Spoiler:
# Write a program that prompts the user for 2 numbers (integers) (a & b).
# Then print out: "The product of a & b is: ", then the product of (a&b).
print('Type 2 intergers numbers')
a = input('first number')
b = input('second number')
# print("The product of a & b is: " + " " + a*b)
# print("The product of a & b is: " + " " + str(a*b)) ##Line 7: SyntaxError: bad input (' ') ##
# print("The product of a & b is: " + " " + (str(a)* str(b)))
# xtrA= str(a)
# xtrB= str(b)
#print("The product of a & b is: " + " " + (xtrA * xtrB))

#xintA= int(a)
#xintB= int(b)
#print("The product of a & b is: " + " " + (xintA * xintB))
print("@#$%#$##@! :-(")
print("The product of a & b is: " + " ")
# print (a*b)
print(int(a)*int(b))
print("Hallelujah! At last!")
"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston

Krikor
Forum Member
12th Place
917 Post(s)

Post#3 by Krikor » 17 Nov 2018, 17:07


tim wrote:
16 Nov 2018, 20:23
Write a program that prompts the user for 2 numbers (integers) (a & b).
Then print out: "The product of a & b is: ", then the product of (a&b).
Solution:
Spoiler:

Code: Select all

a = input("Enter a:")
b = input("Enter b:")
a = int(a)
b = int(b)
print ("The product of a & b is: " + str(a*b))
Tim,
Tim, I tried to show the answer in one line. The program runs and gives the right answer, yet it displays an error code.

Is it possible to display two or more Print () on the same line?
Spoiler:
a = input("Enter a:") <The product of a & b is:>
b = input("Enter b:") <15>
a = int(a)
b = int(b)
print ("The product of a & b is: ") + print(a*b) <Line 5: NameError: Undefined variable in expression>
"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston

tim
GL Blogger
1st Place
5541 Post(s)

Post#4 by tim » 17 Nov 2018, 18:01


Yes you can
Example:
Spoiler:
print ("Hello ",end=""); print ("Tim")
you end one print with semicolon, and to make print not print a new line so that the next print is on the same line you just pass in an extra named parameter called end and make it blank so it doesn't print a new line character
aka Tin
World Food Program | Good Deeds Forum

         


GIMP/GL:  Tutorials | Tips | Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | 🡆 Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Post Reply New Topic
  • Similar Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 1 guest