Skip to main content

Posts

Showing posts with the label Python

Python program to count unique letters in any given string or paragraph

To count the unique letters in any given string and paragraph we can use python dictionary object and its indexing method. Below the program of counting unique alphabets, white spaces and dashes. Python Program or code: import string #Include " " to count it alphabet = string.ascii_letters + " " + " -- " #print(alphabet) sentence = 'Jim quickly realized that the beautiful gowns are expensive' address = """Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper ...

SoloLearn Python Core: celsius to fahrenheit converter code project answer

Code project answer of  SoloLearn mobile Application and project celsius to fahrenheit converter code from Python Core course. celsius = int(input()) def conv(c):      celsius = c f = 9/5 * celsius + 32 return f fahrenheit = conv(celsius) print(fahrenheit) In this code we just need to declare a variable, we can name it as 'f' and assign values of equation of Fahrenheit to Celsius convertor equation (9/5 * Celsius + 32), and return that variable f and print it. What is happening here is. In the first line we take one 'int' or 'whole number' as input and then we call the function 'conv' which returns converted value f. Then we simply take or copy that return variables data to our new variable called 'fahrenheit', and then we are going to print it.

SoloLearn Python Core: functions and modules quiz answer

 This is a quiz answer of module 4, Python Core course of SoloLearn mobile application. This is final quiz appear after module 4 functions and modules. 1. Fill in the blanks to define a function that takes two number as argument and returns smaller one. Ans. def min (x, y):      if x <= y:      return x else: return y 2. Rearrange the code to define a function that calculates the sum of all numbers from 0 to its argument. Ans . Def sum (x):      res = 0 for i in range (x): res += i return res 3. How would you refer to the randint function if it was imported like this?  from random import random as rnd_int. Ans . rnd_int 4. What is the highest number output by this code? def print_nums(x): for i in range(x): print(i) return print_nums(10) Ans. 0 5. What is the output of this code? def funct (x):      res = 0 for i in range(x):      res ...

Sololearn Python Core code project FizzBuzz answer

 FizzBuzz is a well known programming assignment, asked during interviews.The given code solves the FizzBuzz problem and uses the words "Solo" and "Learn" instead of "Fizz" and "Buzz". It takes an input n and outputs the numbers from 1 to n. For each multiple of 3, print "Solo" instead of the number. For each multiple of 5, prints "Learn" instead of the number. For numbers which are multiples of both 3 and 5, output "SoloLearn".  You need to change the code to skip the even numbers, so that the logic only applies to odd numbers in the range. Ans. for x in range(1, n , 2): if x % 3 == 0 and x % 5 == 0: print("SoloLearn") continue elif x % 3 == 0: print("Solo") continue elif x % 5 == 0: print("Learn") continue else: print(x)

Sololearn quiz answers for python Core: Control structure

 Sololearn mobile application quiz answers for Python Core programming of module control structure: 1. What is the output of this code? list = [1,1,2,3,5,8,13] print(list[list[4]]) Ans. 8 2. What does this code do? for i in  range(10):     if not i % 2 == 0:          print(i+1) Ans: Print all the even numbers between 2 and 10. 3. How many lines will this code print? While False:     print("Looping...") Ans. 0 4.Fill in the blank to print the first element of the list, if it contains even number of elements. Ans. list[1,2,3,4]          if len(list) % 2 == 0:               print(list[0]) 5. What does this code output? letters ['x','y','z'] letters.insert(1,'w') print(letters[2]) Ans. y 6. Fill in the blanks to iterate over the list using for loop and print its values. Ans. list = [1,2,3] for var in list:     print(var)

Python Vs C++ | Will python can be used as alternative of C++

Python is handy tool nowadays in this fastest growing scientific world. In all field of science and technology uses hardware and software integration to develop and test ideas or innovate something. This could be the main reason that why everyone talk so much about different computer languages. So for computer geeks it will easy to understand core difference between different languages. courtesy But for beginners, it is hard to choose which language is best , because every language has its own purpose and advantages. For example if mechanical student want to implement some equation or algorithm then it can be implemented in all most all computer languages. Here are some factors that beginners consider to choose particular language. Factors that considered by beginners to choose computer language 1. Based on syntax structure 2. Organization preference [if school/college uses any particular one] 3. Availability of technical helps and tutorials 4. Inspired by someone...

How to Solve The Towers Of Hanoi in Python | Recursive programming

The tower of Hanoi is most popular and very interesting puzzle.Let me explain the puzzle first, there are three towers given let say X , Y , and Z. and No. of Discs are placed on that tower in descending order(Large Disc to Small) let say 3 Disc.Now in idle condition all disc are placed in Tower A with Descending order.Now your task is to place that Discs in to last tower Z as Descending order. But The rules ,Which we have to take into account before moving a Discs Are: (1) Only one disc may be moved at a time. (2) Only top disc on any Peg may be moved to any other Peg. (3) A larger disc can not be placed on a smaller one. Source Python Program to Solve The Tower of Hanoi : This is the Example of Recursive programming in python with Function calling. n = int(raw_input("Enter no of Disc to solve Tower\n >")) def hanoi_tower(peg1, peg2, peg3, n): if n <= 0: print "Dont be over smart" return if n == 1: print ...