Python‎ > ‎Built-in‎ > ‎

input()

http://www.adilwaseem.com/
Introduction
The method store information written in input() and and return it into string values.

Syntax
input(x)

Parameters
x=number, string

Examples
The input method declared equal to variable.
 >>> a=input("")
hello
>>> a
'hello'
>>>
>>> b=input('')
You're Python Lake?
>>> b
"You're Python Lake?"
>>>

int(input())
The input() returns with integer.
 >>> int(input(" Enter your number: "))
Enter your number: 12
12

str(input())
The input() returns with string.
 >>> str(input(" Enter your string value: "))
Enter your string value: 120
'120'

tuple(input())
The input() returns with tuple().
 >>> tuple(input("Enter your number: "))
Enter your number: Python Lake
('P', 'y', 't', 'h', 'o', 'n', ' ', 'L', 'a', 'k', 'e')

list(input())
The input() returns with list.
 >>> list(input("Enter your number: "))
Enter your number: Adil
['A', 'd', 'i', 'l']

len(input())
The input() returns with length.
 >>> len(input("Enter your name: "))
Enter your name: Adil
4

chr(input())
The input() returns with character.
 >>> chr(int(input("Enter your integer; ")))
Enter your integer; 445
'ƽ'


capitalizing input(str)
The method returns with capitalizing the input().
 name1=input("Enter your name: ")
if name1.lower():
print("Your name is: ", name1.capitalize())
>>> 
Enter your name: adil
Your name is: Adil
>>> 


input() value tested through if statement
Here in this sample code the variable assigned the numeric ranges and and if statement is tested on these variables.
a=range(1,18)
b=range(18,40)
c=range(40,99)
print("Please enter your age")
d=input()
if d is a:
    print("You're authorized to work")
elif d is b:
    print ("You are authorized to work")
else:
    print("You can request accommodation")

>>>
Please enter your age

28
You can request accommodation
>>>

math.cos()
The method input() is used to get the math.cos() value.
 import math
x=int(input("Please enter your Cosine numeric value: "))
print ("Your cosine value is: ", math.cos(x))
>>> 
Please enter your Cosine numeric value: 2
Your cosine value is: -0.4161468365471424

The input() value returns the math.sin(a)*2-1
import math
import operator
a=float(input("Please enter sine(value) : "))
b=math.sin(a).__mul__(2).__sub__(1)
print(b)
>>> 
Please enter sine(value) : 2.2
0.6169928076391802
>>>


float(input())
The equation value is determined through input().
import math
import operator
a=float(input("Please enter copysign(x) : "))
b=float(input("Please enter copysign(y) : "))

c=math.copysign(a,b).__add__(1.1).__mul__(math.acosh(2)).__truediv__(math.atan2(88,34))
print("The equation value is", c)

>>> 
Please enter copysign(x) : 2
Please enter copysign(y) : 6
The value is 3.3961966891396522
>>> 


if statement 
The method str.isalpha() is tested str(input()) through if statement.
 Name=str(input("Please enter your name: "))
if str.isalpha(Name):
print("Name can be single character.")
else:
print("Okay")
>>> 
Please enter your name: p
Name can be single character
>>>


The method is equal to:
 name1=input("Enter your name: ")
name1.expandtabs()
print("Your name is: ", name1)

>>> 
Enter your name: Adil
Your name is:    Adil

if statement(input())
Return with round value of random.betavariate()+(random.gammavariate().
import random
x=round((random.betavariate(3,1))+(random.gammavariate(3,21)))
if x in range(1,9):
    print("The random value is single digit: ", x)
    y=input("Do you add to generate number one more time: y/n")
    if y=="y":
        print("Second random value is: ", round((random.betavariate(3,1))+(random.gammavariate(3,21))))
            elif y=="n":
                next
elif x in (range(10,99)):
    print("Random value is: ", round((random.betavariate(3,1))+(random.gammavariate(3,21))))
    z=input("Do you add to generate number one more time: y/n: ")
    if z=="y":
        print("Second random value is: ", round((random.betavariate(3,1))+(random.gammavariate(3,21))))
    elif z=="n":
        next
else:
print("Random value is: ", round((random.betavariate(3,1))+(random.gammavariate(3,21))))


while loop: input() 
The loop returns with: 
 while True:
    try:
        print("Please enter password: ")
        x=input()
        password=int(x)
        print("Please enter correct password: ", password, "is not correct")
    except:
        print("password: " ,password, "is not correct")
        break    

>>> 
Please enter password: 
152
Please enter correct password:  152 is not correct
Please enter password: 

Return with perimeter of bedroom through input().
print("Python Lake will find Perimeter, please enter following information")
l=int(input("Enter length of bedroom: "))
w=int(input("Enter length of width: "))
p= 2*l+2*w
print("Perimeter of Bedroom is " ,p,)
>>> 
Python Lake will find Perimeter, please enter following information
Enter length of bedroom: 10
Enter length of width: 15
Perimeter of Bedroom is 50
>>>


input()....class....: def....: str.find()...str.count..
The function allow the user to find word in their text.
 class method_text_finder():
    def __init__(self, a,b):

        self.a=str(a)
        find1=a.find(b)
        print("The word found in your text at position:",find1+1)

        count1=a.count(b)
        print("The total word found in your text:",count1)

text=input("Please enter your text: ")
find_word=input("Please enter your text:")

method_text_finder(text,find_word)

>>> 
Please enter your text: Python Research Centre is located at Woodbridge Va
Please enter your text:Woodbridge
The word found in your text at position: 38
The total word found in your text: 1
>>> 


Here is how Error method printed the error message.
 import webbrowser

x=input("Please enter web dress:")

if x.__eq__('www.pythonlake.com'):
    webbrowser.open(x)

    webbrowser.Error("Not allowed to access the file")

>>> 
Please enter web dress:www.amazon.com
Not allowed to access the file
>>> 


input(webbrowser.open_new())
webbrowser.open_new()
 import webbrowser

x=input("Please enter your web address: ")
y=str(x)

if y.startswith("y"):
    print("Access denied")
    webbrowser.open_new(y)

>>> 
Please enter your web address: yellow.com
Access denied


tkinter.Label(text=input())
The label value is get through  input():
 from tkinter import Tk
import tkinter

master=tkinter.Tk()

a=tkinter.Label(master, text=input("Please enter your Label: ")). pack()

master.mainloop()
              
>>> 
Please enter your Label: Python Lake
>>>




int(input(Arc values))
The arc is created through tkinter.Canvas().Create_arc() through user input().
from tkinter import*
import tkinter
    
master=tkinter.Tk()

def create_arc1():
    canvas=tkinter.Canvas(master, width=250, height=300)
    canvas.pack()

    x1_value=input("Please enter x1 arc value :" )
    x1=int(x1_value)

    y1_value=input("Please enter y1 arc value :" )
    y1=int(y1_value)
    
    x2_value=input("Please enter x1 arc value :" )
    x2=int(x2_value)
    
    y2_value=input("Please enter x1 arc value :" )
    y2=int(y2_value)

    canvas.create_arc(x1, y1, x2, y2)
        
button=tkinter.Button(master, text="Create Arc",command=create_arc1).pack()






>>> 
Please enter x1 arc value :50
Please enter y1 arc value :110
Please enter x1 arc value :150
Please enter x1 arc value :250
>>> 


Comments