How to translate this c++ code in python?

#include <fstream>
using namespace std;
int get_count(int prev_level, int n) {
 if (0 == n)
 return 1;

 int count = 0;
 for (int level = 1; level < prev_level; ++level) {
 if ((n - level) < 0) 
break;
 count += get_count(level, n - level);
}

 return count;
}

int main() {
 ifstream ifst("input.txt");
 ofstream ofst("output.txt");
 int n, count = 0;
 ifst >> n;
 ofst << get_count(n+1, n);
}
April 4th 20 at 00:36
1 answer
April 4th 20 at 00:38
Solution
So

n = int(input())

def get_count(prev_level, n):
 if (0 == n):
 return 1

 count = 0
 for level in range (1, prev_level):
 if ((n - level) < 0):
break
 count = count + get_count(level, n - level)
 return count

print (get_count(n+1, n))
Thank you!) - Ocie.Gleason18 commented on April 4th 20 at 00:41

Find more questions by tags Python