• Register
1 vote
248 views

Problem:

I am new in python programming language and I am very confused about programming logics. Supose, someone has given two already defined variables, i and j, write a statement that swaps their associated values.

Can anyone help me with this problem?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

1 vote
 
Best answer

Answer:

To swap the values you should use the code or the statement:

i = input('Please enter value of i: ')
j = input('Please enter value of j: ')


temp = i
i = j
j = temp

print('The value of i after swapping: {}'.format(i))
print('The value of j after swapping: {}'.format(j))

Run this and your output will be:

Please enter value of i: 2
Please enter value of j: 4
The value of i after swapping: 4
The value of j after swapping: 2

Hope this help you.

11 6 4
34,950 points

Related questions

0 votes
1 answer 25 views
25 views
Problem: Given that play_list has been defined to be a list, write a statement that sorts the list?
asked Mar 9, 2020 ArifulIslam 7.5k points
0 votes
2 answers 199 views
199 views
Problem : I need solution for below problem using Python Given that play_list has been defined to be a list, write a statement that sorts the list.
asked Nov 24, 2019 alecxe 7.5k points
0 votes
2 answers 50 views
50 views
Problem: Given the array a, write an expression that refers to the first element of the array?
asked Apr 12, 2020 ArifulIslam 7.5k points
0 votes
1 answer 2 views
2 views
Problem: Given an unsorted array, find the max j - i difference between indices such that j > i and a[j] > a[i] in O(n). I am able to find j and i using trivial methods in O(n^2) complexity but would like to know how to do this in O(n)? Please help?
asked Apr 10 Sana8989 8.9k points
0 votes
1 answer 2 views
2 views
Question: I know this might seem like an absolutely silly question to ask, yet I am too curious not to ask. Why did "i" and "j" become THE variables to use as counters in most control structures? Although common sense tells me they are just like X, which is ... have some obscure reason behind it? Just in case, I know I can give them whatever name I want and that variables names are not relevant.
asked Apr 12 Atik03 14.9k points
0 votes
1 answer 29 views
29 views
Problem: write a method swaparrayends() that swaps the first and last elements of its array parameter.
asked Feb 23 Hira 2.2k points
0 votes
2 answers 85 views
85 views
Problem: In C++, you can create aliases to a previously defined data type by using the ____ statement?
asked Apr 12, 2020 ArifulIslam 7.5k points
0 votes
1 answer 160 views
160 views
I started programming recently, I have learned some basic programming topics like loops, array and many more. But they are not enough to implement my concept in java. I can write a void method that can take 2 or more parameters and print the summation of all parameters. But now I want to ... * @param a * @param b */ public static void add(int a, int b){ int sum = a+b; System.out.println(sum); }
asked May 3, 2020 samhaz 5k points
0 votes
1 answer 216 views
216 views
Problem: I am new in programming and stuck in a query, can anyone guide me? Write an expression that evaluates to True if the str associated with s starts with "p"?
asked Feb 17, 2020 maddi86 5.4k points