Skip to main content

Posts

Popping element from list in python

  Modify short_names by deleting the first element and changing the last element to Joe Sample output with input : "Jig Jag Jam Jim" ['Jag', 'Jam', 'Joe'] user_input = input() short_names = user_input.split() short_names.pop(0) short_names[-1] = 'Joe' print(short_names) Hope this is helpful. Write back to me in case you need help with your python task. I generally reply back within 24 hours. You can connect with me on Whatsapp also: +918602715108

Python program from reversing a number, calculating number of digits

Write a program to reverse a number entered by the user. Call your program int_reverser.py . Suggested approach:  a. Write an expression for the number of digits. This is the log in base 10 , math.log100, but it should be a whole number.  b. Write a loop to keep dividing the number by 10 and printing the remainder.  c. Add an accumulator variable for the result. Keep multiplying the result by 10 and adding the remainder. Example usage:  Integer reverer  Integer: 1234  4321  import math n = int(input("Enter number: ")) numberOfDigit = math.log10(n) if n Enter number: 1234 4321 Hope this is helpful. Write back to me in case you need help with your python task. I generally reply back within 24 hours. You can connect with me on Whatsapp also: +918602715108

Prime Number program in Python

A prime number is a number that has only two factors: 1 and the number itself. For example, 2, 3, 5, 7 and 11 are the first few prime numbers. Write a program that repeatedly prompts a user for numbers until the user enters a positive larger number. Once a valid number is entered, print out the list of prime number from 0 to the entered number. If the user enters anything other than a valid number MO it with a try/except and put out an appropriate message and ignore the number. For example, enter -1, bob and 10 and match the output below.  Enter a positive integer number: -1  The number must be positive.  Enter a positive integer number: bob  The number must be a positive number.  Enter a positive integer number: 10  The prime numbers from 0 to 10: 2 3 5 7  while True: try: n = int(input("Enter a positive integer number: ")) if n <= 0: print("The number must be a positive.") else: print("The...