print("Hello, World!") # Hello World program in Python print ("Hello World") print("Hello World") print("|___|") print("|___|") print("\___/") print("\___/") print(" ???") character_name = "IMPERIAL BLOXY" character_age = "38.16532" is_Male = True print("There was a man named " + character_name + ",") print("he was 38 years old.") print("he really liked the name " + character_name + ",") print("But didn't like being " + character_age + ".") print("hello world today you become orange as the sun and explode and almost all of the planets will be gone.") print(" Girrafe Academy is trash but learing at the same time and python is fun") print("Giraffe\"Academy") print("girrafe\nacademy") print("Girrafe Academy") phrase = "Giraffe Academy" print(phrase + " is cool") print(phrase. lower()) print(phrase.upper()) print(phrase.isupper()) print(phrase.upper().isupper()) print(len(phrase)) print(phrase[0]) print(phrase[3]) print(phrase.index("G")) print(phrase.index("a")) print(phrase.index("Acad")) print(phrase.index("m")) print(phrase.replace("Giraffe","Elephant")) print(2) print(-2,2979) print(3+121) print(3%122) print(12*13) print(1234*452) print(746723564*265544538) print(213223-213463585) print(1213*213+324) print(213*(213244+233456)) my_num=5 print(abs(my_num)) #name = input("enter you name:") name = "prithvi" #age = input("enter you age:") age='10' print ("hello" + name + "!you are" + age) #num1= input ("enter a number:10") num1 = 5 #num2= input ("enter another number:5") num2 = 10 result = num1 + num2 print(result) num1 = 5 num2 = 10 #result = int(num1) + int(num2) #result = float(num1) + float(num2) #color = input ("enter a color:blue") #plural_noun = input ("enter a plural noun:violets") #celebrity = input ("enter a celebrity: rainmator") print("roses are red") print(" violets are blue") print("i love rainmator") friends = ["kevin","Karen","jim","Oscar","Toby"] #0 1 2 3 4 friends[1] = "mike" print(friends[1:]) coordinates = (4, 5), (6, 7), (80, 34) coordinates[1] print(coordinates[1]) def say_hi():("hello user") print("hello user") def cube(num): return num*num*num print(cube(100000000000)) print(result) is_male = True is_tall = False if is_male or is_tall: print("you are a tall male") elif is_male and not(is_tall): print("you are a short male") elif not (is_male) and not is_tall: print("you are a short male") else: print("you either not male or not tall or both") def max_num(num1, num2, num3): if num1 >= num2 and num1 >= num3: return num1 elif num2 >= num1 and num2 >= num3: return num2 else: return num3 print(max_num(3,40,5)) def say_hi(name, age): print("hello" + ", you are " + str(age)) say_hi("mike",35) say_hi("Steve",70) #num1 = float(input("enter first number: ")) num1 = float(78909999.999) #op = input("enter operator: ") op = "+" #num2 = float(input("enter second number: ")) num2 = float(35564656.8889) if op == "+": print(num1 + num2) elif op == "-": print(num1 - num2) elif op == "/": print(num1 / num2) elif op == "*": print(num1 * num2) else: print("Invalid operator") monthConversions = { "1": "January", "2": "February", "3": "March", "4": "april", "5": "May", "6": "june", "7": "july", "8": "august", "9": "september", "10": "october", "11": "november", "12": "december", } print(monthConversions.get("12")) i = 1 while i <= 10: print(i) i += 1 print("done with loop") secret_word = "giraffe" guess = "" guess_count = 0 guess_limit = 10 out_of_guesses = False while guess != secret_word and not(out_of_guesses): if guess_count < guess_limit: #guess = input("enter guess:") guess = 5 guess_count+= 1 else: out_of_guesses = True if out_of_guesses: print("out of guesses, you lose!") else: print("you win!") friends = ["jim","Karen","kevin"] for index in range(5): if index==0: print("first iteration") else: print("not first")
Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language, supporting both the versions which are Python 3 and Python 2.7. Getting started with the OneCompiler's Python editor is easy and fast. The editor shows sample boilerplate code when you choose language as Python or Python2 and start coding.
OneCompiler's python online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample python program which takes name as input and print your name with hello.
import sys
name = sys.stdin.readline()
print("Hello "+ name)
Python is a very popular general-purpose programming language which was created by Guido van Rossum, and released in 1991. It is very popular for web development and you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It is designed to be simple and easy like english language. It's is highly productive and efficient making it a very popular language.
When ever you want to perform a set of operations based on a condition IF-ELSE is used.
if conditional-expression
#code
elif conditional-expression
#code
else:
#code
Indentation is very important in Python, make sure the indentation is followed correctly
For loop is used to iterate over arrays(list, tuple, set, dictionary) or strings.
mylist=("Iphone","Pixel","Samsung")
for i in mylist:
print(i)
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while condition
#code
There are four types of collections in Python.
List is a collection which is ordered and can be changed. Lists are specified in square brackets.
mylist=["iPhone","Pixel","Samsung"]
print(mylist)
Tuple is a collection which is ordered and can not be changed. Tuples are specified in round brackets.
myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
Below throws an error if you assign another value to tuple again.
myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
myTuple[1]="onePlus"
print(myTuple)
Set is a collection which is unordered and unindexed. Sets are specified in curly brackets.
myset = {"iPhone","Pixel","Samsung"}
print(myset)
Dictionary is a collection of key value pairs which is unordered, can be changed, and indexed. They are written in curly brackets with key - value pairs.
mydict = {
"brand" :"iPhone",
"model": "iPhone 11"
}
print(mydict)
Following are the libraries supported by OneCompiler's Python compiler
Name | Description |
---|---|
NumPy | NumPy python library helps users to work on arrays with ease |
SciPy | SciPy is a scientific computation library which depends on NumPy for convenient and fast N-dimensional array manipulation |
SKLearn/Scikit-learn | Scikit-learn or Scikit-learn is the most useful library for machine learning in Python |
Pandas | Pandas is the most efficient Python library for data manipulation and analysis |
DOcplex | DOcplex is IBM Decision Optimization CPLEX Modeling for Python, is a library composed of Mathematical Programming Modeling and Constraint Programming Modeling |