• Home
  • Kembara's Health Solutions
  • Kembara's Language Solutions
  • Kembara's Engineering, Scientific and Mathematical Solutions
  • Kembara's Legal Infos
  • Kembara's Financial Solutions
  • Kembara's Computing Solutions
  • Kembara's Psychological Solutions
  • Kembara's Culinary and Travel's Solutions
  • Sejarah Malaysia
  • General Facts
  • About Me
  • Contact
  • The Foundation of Islamic Finance
  • General Facts of Islamic Finance
  • Conventional Banking and Riba( (interest)
  • The Relationship between the Bank, Customers and Users of Fund in Islamic Banking
  • Islamic Insurance Takaful
  • Basic Facts of Islamic Capital Markets

Kembara's Computing Solutions

Python Programming Language-User Input

7/27/2022

0 Comments

 
Python Programming Language-User Input 
We have merely printed text onto the screen up until this point. However, we also have the option of entering our own data into the script. In this chapter, we'll examine user input and how to deal with it.
Input Function 
 We may retrieve user input from the console application using Python's input method. 

input = name ("Enter your name here:") print(name) 

The user's name is saved into the variable name when entered here. This variable can then be called and printed. 

number1 = input ("Enter first number: ") number2 = input ("Enter second number:") 
sum = number1 + number2 
print("Result: ", sum) 

This illustration is a little deceptive. It appears that we are printing the sum after receiving two numbers as input. The function input always returns a string, which is a concern. As a result, when you enter 10, the variable's value is "10," which is a string. What occurs when we combine two strings, then? Simply put, we add one to the other. As a result, "15" and "26" would equal "1526" when added together. 


We must first typecast our variables if we wish to perform a mathematical addition. 

number1 = input("Enter first number: ")
number2 = input("Enter second number: ")
number1 = int(number1)
number2 = int(number2)
sum = number1 + number2
print("Result: ", sum)



Our script is now effective. Always keep in mind that the input function returns a string, so if you wish to perform computations with it, you must typecast it.
Picture
Picture
0 Comments



Leave a Reply.

    Author

    Anything you need to know about computer science 

    Archives

    May 2023
    April 2023
    March 2023
    February 2023
    August 2022
    July 2022
    May 2022
    April 2022
    February 2022
    November 2021
    October 2021

    Categories

    All
    Computer Science
    Computing Dictionary
    How To Build Iphone Apps
    HTML
    Mathematics For Computer Science
    Python Programming Language
    Video Games Review

    RSS Feed

Proudly powered by Weebly
  • Home
  • Kembara's Health Solutions
  • Kembara's Language Solutions
  • Kembara's Engineering, Scientific and Mathematical Solutions
  • Kembara's Legal Infos
  • Kembara's Financial Solutions
  • Kembara's Computing Solutions
  • Kembara's Psychological Solutions
  • Kembara's Culinary and Travel's Solutions
  • Sejarah Malaysia
  • General Facts
  • About Me
  • Contact
  • The Foundation of Islamic Finance
  • General Facts of Islamic Finance
  • Conventional Banking and Riba( (interest)
  • The Relationship between the Bank, Customers and Users of Fund in Islamic Banking
  • Islamic Insurance Takaful
  • Basic Facts of Islamic Capital Markets