Posts

Showing posts from February, 2021

Functions

 Here I have shown you some basic examples and syntax on how to use  functions in python - 1)a=8 b=9 c=sum((a,b)) print(c) 2)def function1(): print("hello") funtion1() Result=hello 3)def function1(a,b): print("sum is",a+b) function1(5,6) Result= sum is 11

Write a Python program that accept an integer (n) and calculate the value of n+nn+nnn.

  n= int ( input ( "enter your number" )) var1= int (n) var2= int (n*n) var3= int (n*n*n) print (var1+var2+var3)

Getting extension of a filename

  fn= str ext= str print ( "enter name before ." ) fn= input () print ( "enter name after ." ) ext= input () print (fn, end = '.' +ext+ " " ) print ( "is it correct" ) if input ()==( "yes" ): print (ext) here we got a code in python which gives the extension name as output of a filename.

Guess the number game using python

  while ( True ): n= int ( input ( "guess your number between 0 and 10" )) if 0 <n< 5 : print ( "thoda bada" ) continue elif n== 5 : print ( "you got me" ) break elif n> 5 : print ( "thoda chota" ) continue here, I have given a code in python which is actually a fun game where you have to guess a number between 1 to 10 and and if you guess it right, you win also you get unlimited guesses in this game although you need max to max 10 of them:-).

A code in python on eligibility to apply for a driving license using if else

print ( "enter your age" ) age= int ( input ()) if 18 <age< 100 : print ( "you can drive" ) elif age== 18 : print ( "you have to appear for a driving test" ) elif age> 100 : print ( "error" ) elif age< 7 : print ( "invalid age" ) elif 7 <age< 18 : print ( "you cannot drive" ) Above code tells us whether a person can issue a driving license or not by taking his or her age as a decisive factor. This code also bans children under 7 or above 100 to apply for the driving license. TIP- if you use elif statement more, there is less chances to get an error because here python checks objectively for the result and does not go to next line if it gets the suitable result on the current elif(else if) statement.

How to make a dictionary in pycharm using python

  d1={ "google" : "browser" , "mouse" : "hardware" , "pen" : "kalam" , "phone" : "chalbhashiyantram" , "harvard" : "college" , "jee" : "exam" } print ( "enter your word" ) word= input () print ( "this word means" ,d1[word]) Above was a simple example of a dictionary made using python code.it can be added with more meanings if required or you can change the keys and their meanings and replace them with new one in the similar way the former were written.