File 1 s qator berilgan. Agar s yaroqli fayl nomi bo’lsa, u holda shu nom bilan bo’sh fayl yarating va true deb chop eting. Agar s nomli fayl yaratilmasa,false deb chop eting. Kod (Python)


Download 6.05 Kb.
bet1/2
Sana19.09.2023
Hajmi6.05 Kb.
#1681563
  1   2
Bog'liq
File 1 s qator berilgan. Agar s yaroqli fayl nomi bo’lsa, u hold-fayllar.org


File 1 s qator berilgan. Agar s yaroqli fayl nomi bo’lsa, u holda shu nom bilan bo’sh fayl yarating va true deb chop eting. Agar s nomli fayl yaratilmasa,false deb chop eting. Kod (Python)

File 1
S qator berilgan.Agar S yaroqli fayl nomi bo’lsa , u holda shu nom bilan bo’sh fayl yarating va TRUE deb chop eting.Agar S nomli fayl yaratilmasa ,FALSE deb chop eting.
Kod (Python)

  1. file_name = input('Fayl nomini kiriting: ')



  2. try:

  3. f = open(file_name, "w")

  4. try:

  5. f.write('')

  6. print('TRUE')


  7. finally:


  8. f.close()


  9. except IOError:


  10. print('FALSE')




File 2
Fayl nomi va N(>1) butun soni berilgan.Berilgan nomli butun sonlardan iborat fayl yarating va unga birinchi N musbat juft sonni (2,4,6 …) yozing.
Kod (C/C++)
#include

  1. using namespace std;



  2. int main()


  3. {

  4. ifstream fin("input.txt");

  5. ofstream fout("output.txt");


  6. int n;

  7. fin >> n;

  8. for(int i = 2; i <= n * 2; i+=2){


  9. fout << i << " ";


  10. }

  11. return 0;

  12. }

Kod (Python)

  1. import random



  2. file_name = "file02.txt"


  3. N = random.randrange(1,10)


  4. try:

  5. f = open(file_name, "w")

  6. f.write("N = " + (str)(N) + '\n')


  7. try:

  8. for i in range(N):

  9. f.write((str)((i+1)*2) + '\n')


  10. finally:


  11. f.close()


  12. except IOError:


  13. print('Fayl yaratilmadi')





File 3
Fayl nomi va haqiqiy sonlar A va D berilgan.Berilgan nomli haqiqiy sonlar faylini tuzing va unga arifmetik progressiyaning dastlabki 10 a’zosini A boshlang’ich a’zosi va D farqi bilan yozing:A,A+D, A + 2·D, A + 3·D, ...
Kod (Python)
  1. import random



  2. N = random.randrange(1,10)


  3. A = random.randrange(-10,10)


  4. D = round(random.uniform(-5,5),1)


  5. print("N = ", N)


  6. print("A = ", A)


  7. print("D = ", D)



  8. a = [A + i*D for i in range(N)]


  9. print(a)



  10. file_name = "file03.txt"


  11. try:

  12. f = open(file_name, "w")

  13. f.write("N = " + (str)(N) + '; ')


  14. f.write("A = " + (str)(A) + '; ')


  15. f.write("D = " + (str)(D) + '\n')


  16. f.write(str(a))


  17. except IOError:


  18. print('Fayl ishlamadi')


  19. finally:


  20. f.close()






Download 6.05 Kb.

Do'stlaringiz bilan baham:
  1   2




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling