Stack and function calls in c++ and python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Stack and function calls in c++ and python

I am new to python.When i implement a dfs code using c++ it works fine but in python it brings me a runtime error.i expect that it might be because of the stack .is there is a different between the way the stack works and function calls in c++ and python.Thanks very much in advance.

30th Jul 2017, 7:12 PM
mariam maher
mariam maher - avatar
31 Answers
+ 1
what do your python code look like and what is it supposed to do, I might be able to just write out what you need to type/change
1st Aug 2017, 1:05 PM
vortetty
vortetty - avatar
+ 1
ok, I will figure it out asap
2nd Aug 2017, 2:08 PM
vortetty
vortetty - avatar
+ 1
for i in range (1,n+1): manager[i]=int(input()) for i in range (1,n+1): what is the 1,n+1 supposed to do
2nd Aug 2017, 2:28 PM
vortetty
vortetty - avatar
+ 1
no, I think I have it working I will tell you soon
2nd Aug 2017, 3:36 PM
vortetty
vortetty - avatar
+ 1
you are welcome! I enjoy helping people!
2nd Aug 2017, 5:16 PM
vortetty
vortetty - avatar
0
define stack
1st Aug 2017, 1:05 PM
vortetty
vortetty - avatar
0
it was a solution for a problem in codeforces .do you want me to include my c++/python code?
1st Aug 2017, 10:42 PM
mariam maher
mariam maher - avatar
0
yes! please!
1st Aug 2017, 11:35 PM
vortetty
vortetty - avatar
0
that is the problem http://codeforces.com/problemset/problem/115/A that is how i solved it in c++ http://codeforces.com/contest/115/submission/29024765 and that is the python code http://codeforces.com/contest/115/submission/29024623 it brings a runtime error although it is identical to the c++ code that is accepted
2nd Aug 2017, 12:10 AM
mariam maher
mariam maher - avatar
0
to loop from 1 to n
2nd Aug 2017, 2:32 PM
mariam maher
mariam maher - avatar
0
ok, in python, you would just put x = n+1 for i in x
2nd Aug 2017, 2:35 PM
vortetty
vortetty - avatar
0
also what are the input for?
2nd Aug 2017, 2:36 PM
vortetty
vortetty - avatar
0
sorry meant inputs, stupid auto correct
2nd Aug 2017, 2:37 PM
vortetty
vortetty - avatar
0
i tried range(1,n+1) in another code and it worked and that is the code https://code.sololearn.com/cGKytcP96kSC/?ref=app for input() i used it to get input from the user
2nd Aug 2017, 2:43 PM
mariam maher
mariam maher - avatar
0
yes, I understand the input reason. is "n" number of employees is "manager" number of managers also you had input set up as an int not a string. solo learn also does not have the best interpreter, I'm using python 3.6.1 so I have the most accurate of them.
2nd Aug 2017, 2:48 PM
vortetty
vortetty - avatar
0
n is the number of employees i set it to an integer to use it as a number.manager is a list containing the manager of each employee
2nd Aug 2017, 2:55 PM
mariam maher
mariam maher - avatar
0
it had a problem with that
2nd Aug 2017, 3:07 PM
vortetty
vortetty - avatar
0
it only counted 1 to n and didn't give the error I will do my best to make it do that
2nd Aug 2017, 3:11 PM
vortetty
vortetty - avatar
0
also, a runtime error means it took to long to respond
2nd Aug 2017, 3:12 PM
vortetty
vortetty - avatar
0
i think if it took long time it will bring time limit exceeded .also in test 39 n (the number of employees)was 2000 the same number in test case 40 on which the code failed so i don't think it is a matter of time
2nd Aug 2017, 3:16 PM
mariam maher
mariam maher - avatar