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 thatThe 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
Hola! Help me with this thank you! Please do a code without using 'def' thank you.
Python - Tree Operation:
Given the following values: 30,23,16,28,28,90,78,7,15 and 46
- Insert all data into a binary tree in order from 30 to 46. The root is 30. (Draw the Tree) .
- Delete node that consists of 90 (Draw the Tree after deletion)
- Arrange updated data (after deleting 90) In order, Preorder and Post order
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, help me with this one. Thank you!
Determine the relationship between trees and graphs. Own words please. Thank you!
Discuss heap and linked list.
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.
The input will be a single line containing a string.
The output should be a single line containing the modified string with all the numbers in string re-ordered in decreasing order.
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
Make a games (or any other kind of program that you find interesting). Make sure you pick something that you are probably capable of doing. The point of this project is to show off your skills, and to create something very playable, with clear instructions and a great user experience. It’s much better to get a simple program working perfectly than to try to make an overly complicated game that ends up being very glitchy. Also, you must be able to competently explain every bit of your code.
Ordered Matrix
Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order.
Input
The first line of input will contain two space-separated integers, denoting the M and N.
The next M following lines will contain N space-separated integers, denoting the elements of each list.
Output
The output should be M lines containing the ordered matrix.
Note: There is a space at the end of each line.
Explanation
For example, if the given M is 3 and N is 3, read the inputs in the next three lines if the numbers given in the next three lines are the following.
1 20 3
30 10 2
5 11 15By ordering all the elements of the matrix in increasing order, the ordered matrix should be
1 2 3
5 10 11
15 20 30Sample Input 1
3 3
1 20 3
30 10 2
5 11 15
Sample Output 1
1 2 3
5 10 11
15 20 30
Sample Input 2
2 5
-50 20 3 25 -20
88 17 38 72 -10
Sample Output 2
-50 -20 -10 3 17
20 25 38 72 88