Jun-18-2020, 09:16 PM
in Python when i enter 0 the loop skipped but in C++ loop will continue
in Python when i enter a character I see a ValueError but in C++ the will skipped
this C++ code is a part of code in univercity and I wrote the Python code for comparison
sorry I can't write better in English
Python:
Enter 1,2,3,E :
in Python when i enter a character I see a ValueError but in C++ the will skipped
this C++ code is a part of code in univercity and I wrote the Python code for comparison
sorry I can't write better in English
Python:
while int(input()): print("-------") print("out of loop")Enter 1,2,3,0 :
Output:1
-------
2
-------
3
-------
0
out of loop
Enter 1,2,3,E :Output:1
-------
2
-------
3
-------
E
Error:ValueError: invalid literal for int() with base 10: 'E'
C++:#include<iostream> #include<conio.h> using namespace std; void main() { int i=1; while(cin>>i) { cout<<"------\n"; } cout<<"press any key to continue ... "; _getch(); }Enter 1,2,3,0 :
Output:1
------
2
------
3
------
0
------
needs more inputs ...Enter 1,2,3,E :
Output:1
------
2
------
3
------
E
press any key to continue ...