Python Answers

Questions answered by Experts: 5 288

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

write a function that takes an array of integers as input and prints the second maximum difference between any two elements from an array in python


Rearrange Numbers in String

Given a string, write a program to re-arrange all the numbers appearing in the string in decreasing order. Note: There will not be any negative numbers or numbers with decimal part.


Input

The input will be a single line containing a string.


Output

The output should be a single line containing the modified string with all the numbers in string re-ordered in decreasing order.


Explanation

For example, if the given string is "I am 5 years and 11 months old", the numbers are 5, 11. Your code should print the sentence after re-ordering the numbers as "I am 11 years and 5 months old".


Sample Input

I am 5 years and 11 months old

Sample Output

I am 11 years and 5 months old


Sample Input

python4 anjali25

Sample Output

python25 anjali4


Sample Input

1python254

Sample Output

254python1



Sample Input

-1pyth-4on 5lear-3ning-2

Sample Output

5pyth4on 3lear2ning1







Rearrange Numbers in String


Given a string, write a program to re-arrange all the numbers appearing in the string in decreasing order. Note: There will not be any negative numbers or numbers with decimal part.




Input

The input will be a single line containing a string.




Output

The output should be a single line containing the modified string with all the numbers in string re-ordered in decreasing order.




Explanation

For example, if the given string is "I am 5 years and 11 months old", the numbers are 5, 11. Your code should print the sentence after re-ordering the numbers as "I am 11 years and 5 months old".




Sample Input


I am 5 years and 11 months old


Sample Output


I am 11 years and 5 months old




Sample Input 


python4 anjali25


Sample Output


python25 anjali4




Sample Input 


I am 2 years and 3 months old. This sentence4 5should be 6rearr7anged8.


Sample Output


I am 8 years and 7 months old. This sentence6 5should be 4rearr3anged2.


Make a game where the computer will guess a random number for different given ranges eg 1-10, 10-20, 30-20. You are given only 5 lives double digits are allowed like 11. the program must return not a number in the given range if you input anything that isnt in the given range for example 1-10; 1,2,3,4,5,6,7,8,9,10. The program should also ask you if u want to play again


Rearrange Numbers in String

Given a string, write a program to re-arrange all the numbers appearing in the string in decreasing order. Note: There will not be any negative numbers or numbers with decimal part.


def IsNum(s):
    try:
        int(s)
        return True
    except ValueError:
        return False
s = input()
words = s.split()
numbers = []
for x in words:
    if IsNum(x):
        numbers.append(int(x))
if len(numbers) < 2:
    print(s)
numbers.sort(reverse=True)
result = ''
for x in words:
    if IsNum(x):
        result += str(numbers[0])
        numbers = numbers[1:]
    else:
        result += x
    result += ' '
print(result[:-1])

but if we are giving "Narendra52 is 12 years and 5 months old" 52 also should be calculated as a separate number but it is not acting like that

The link below is the photo of the problem. Please create a code without using def

Determine in order, post order and pre order



https://www.bartleby.com/questions-and-answers/52-37-64-24-39-59-73-19-29-56-in-order-pre-order-post-order/100dd94b-74dc-49e0-a700-97b1a7f6afbd


Determine the in-order, pre-order, and post-order sequence of the following: 2 7 5 2 6 9 5 11 4 30 (20 (39 10 25 35 (42 15 23


Vowel Sound


Given a sentence, write a program rotate all the words left, so that every word starts with a vowel.

Note: If there is no vowel in the word, do not rotate it.

Sample Input

I saw a DRAGON flying in the sky

Sample Output

I aws a AGONDR ingfly in eth sky


def vowels_rotate(arg):

    vowels =['a', 'e', 'i', 'o', 'u']

    for indx, letter in enumerate(arg):

        if letter.lower() in vowels:

            return arg[indx:]+arg[:indx]

    return arg 

user_str = input("Enter your string: ")

words = user_str.split()

for i in range(len(words)):

    words[i] = vowels_rotate(words[i])

print(*words,sep="  ")


In the above code using enumerate to get the expected output. But, should we write without using enumerate ?


Hi, please help me with this one. Thank you. Question is below and link of photo. Needed it already. Thanks!


Determine the in-order, pre-order and post-order sequence. The link below is where the photo of this problem. Thank you!


https://www.bartleby.com/questions-and-answers/52-37-64-24-39-59-73-19-29-56-in-order-pre-order-post-order/100dd94b-74dc-49e0-a700-97b1a7f6afbd


Rearrange Numbers in String

Given a string, write a program to re-arrange all the numbers appearing in the string in decreasing order. Note: There will not be any negative numbers or numbers with decimal part.

Input

The input will be a single line containing a string.

Output

The output should be a single line containing the modified string with all the numbers in string re-ordered in decreasing order.

Explanation

For example, if the given string is "I am 5 years and 11 months old", the numbers are 5, 11. Your code should print the sentence after re-ordering the numbers as "I am 11 years and 5 months old".


Sample Input

I am 5 years and 11 months old

Sample Output

I am 11 years and 5 months old


Sample Input

I am 2 years and 3 months old. This sentence4 5should be 6rearr7anged8. If possible -9these negative-12 nums


Sample Output

I am 12 years and 9 months old. This sentence8 7should be 6rearr5anged4. If possible 3these negative2 nums



LATEST TUTORIALS
APPROVED BY CLIENTS